1. Make own review sheet
  2. Practice problems with LLM
  3. Come up with own practice problems

1: Given rods of varying length, see if a combined rod of length is possible (can reuse rods)

knapsack

A. Precise subproblems

Can we form some length using the available rod lengths?

B. Base Case and Recurrence

  1. if some length is equal to a single rod length, then true
  2. length 0 can be made

Recurrence

for any length in the input set

Show solution to original problem can be found by solving problems

Since the algorithm solves for any length , we can find length .

order for subproblems

linear starting from length to length since we have to use subproblems we already solved to get a .

running time

since we run for each state, then for each given rod length. Therefore, .

2. Given three strings X, Y, and Z, return true if Z is X and Y interweaved (X and Y are subsequences in Z)

First iteration: check if first element in Z is the first element of X or Y

Subproblems Definition

Is an element in X or Y and has X(i - 1) or Y(i - 1) true?

Base Case and Recurrence

An element is true if X[i] == Z[i + j]and is true, or and ]

Show Solu obtained from Subproblems

We can check if a string Z is a combination of X and Y by incrementally checking subsequences where

Determine order received subproblems

Start from first element to last

running time

because we go through 2d matrix

Min sum grid traversal (top-left to bottom-right)

Precise Subproblem

What is the minimum sum moving from to ?

Base Case + Recurrence

Base Case is the integer at We set to 0 and to 0

Recurrence

Solu can be obtained from subproblems

Since we can get min sum at an arbitrary , we can get min sum for

order

solve first which corresponds to and go for each elem in row for each col

running time

for looping through matrix

6.3 Yuckdonald Max Profit

Subproblems:

At a location , set

Either take and add to profit - k or don’t take and maintain last one What is the max profit if we either open a restaurant at a location and the location k miles away, or don’t open one and take the last one?

Recurrence

Base case at 0 is 0