# Difference between revisions of "Chapter 10"

Jump to navigation
Jump to search

Line 3: | Line 3: | ||

===Elementary Recurrences=== | ===Elementary Recurrences=== | ||

− | :[[10.1]] | + | :[[10.1]]. Up to <math>k</math> steps in a single bound! A child is running up a staircase with <math>n</math> steps and can hop between 1 and <math>k</math> steps at a time. Design an algorithm to count how many possible ways the child can run up the stairs, as a function of <math>n</math> and <math>k</math>. What is the running time of your algorithm? |

+ | [[10.1|Solution]] | ||

− | :10.2 | + | :10.2. Imagine you are a professional thief who plans to rob houses along a street of <math>n</math> homes. You know the loot at house <math>i</math> is worth <math>m_i</math>, for <math>1 ≤ i ≤ n</math>, but you cannot rob neighboring houses because their connected security systems will automatically contact the police if two adjacent houses are broken into. Give an efficient algorithm to determine the maximum amount of money you can steal without alerting the police. |

− | :[[10.3]] | + | :[[10.3]]. Basketball games are a sequence of 2-point shots, 3-point shots, and 1-point free throws. Give an algorithm that computes how many possible mixes (1s,2s,3s) of scoring add up to a given <math>n</math>. For <math>n</math> = 5 there are four possible solutions: (5, 0, 0), (2, 0, 1), (1, 2, 0), and (0, 1, 1). |

+ | [[10.3|Solution]] | ||

− | :10.4 | + | :10.4. Basketball games are a sequence of 2-point shots, 3-point shots, and 1-point free throws. Give an algorithm that computes how many possible scoring sequences add up to a given <math>n</math>. For <math>n</math> = 5 there are thirteen possible sequences, including 1-2-1-1, 3-2, and 1-1-1-1-1. |

− | |||

− | |||

− | |||

+ | :[[10.5]]. Given an <math>s × t</math> grid filled with non-negative numbers, find a path from top left to bottom right that minimizes the sum of all numbers along its path. You can only move either down or right at any point in time. | ||

+ | ::(a) Give a solution based on Dijkstra’s algorithm. What is its time complexity as a function of <math>s</math> and <math>t</math>? | ||

+ | (b) Give a solution based on dynamic programming. What is its time complexity as a function of <math>s</math> and <math>t</math>? | ||

===Edit Distance=== | ===Edit Distance=== |

## Revision as of 22:17, 11 September 2020

## Contents

# Dynamic Programming

### Elementary Recurrences

- 10.1. Up to steps in a single bound! A child is running up a staircase with steps and can hop between 1 and steps at a time. Design an algorithm to count how many possible ways the child can run up the stairs, as a function of and . What is the running time of your algorithm?

- 10.2. Imagine you are a professional thief who plans to rob houses along a street of homes. You know the loot at house is worth , for
**Failed to parse (syntax error): {\displaystyle 1 ≤ i ≤ n}**, but you cannot rob neighboring houses because their connected security systems will automatically contact the police if two adjacent houses are broken into. Give an efficient algorithm to determine the maximum amount of money you can steal without alerting the police.

- 10.3. Basketball games are a sequence of 2-point shots, 3-point shots, and 1-point free throws. Give an algorithm that computes how many possible mixes (1s,2s,3s) of scoring add up to a given . For = 5 there are four possible solutions: (5, 0, 0), (2, 0, 1), (1, 2, 0), and (0, 1, 1).

- 10.4. Basketball games are a sequence of 2-point shots, 3-point shots, and 1-point free throws. Give an algorithm that computes how many possible scoring sequences add up to a given . For = 5 there are thirteen possible sequences, including 1-2-1-1, 3-2, and 1-1-1-1-1.

- 10.5. Given an
**Failed to parse (syntax error): {\displaystyle s × t}**grid filled with non-negative numbers, find a path from top left to bottom right that minimizes the sum of all numbers along its path. You can only move either down or right at any point in time.- (a) Give a solution based on Dijkstra’s algorithm. What is its time complexity as a function of and ?

(b) Give a solution based on dynamic programming. What is its time complexity as a function of and ?

### Edit Distance

- 10.6

- 10.8

- 10.10

### Greedy Algorithms

- 10.12

- 10.14

### Number Problems

- 10.16

- 10.18

- 10.20

- 10.22

- 10.24

- 10.26

### Graphing Problem

- 10.28

### Design Problems

- 10.30

- 10.32

- 10.34

- 10.36

- 10.38

### Interview Problems

- 10.40

Back to Chapter List