Dynamic Programming Longest Palindrome
What are the base and recursive cases?
Base Case:
Recursive Cases:
Dynamic Programming Longest Palindrome
What does i and j refer to?
What does subProbSols[i][j] refer to?
What location returns the optimal solution?
i refers to the start of the section we are reviewing, j refers to the end
in our two dimensional table, the first index refers to i value, second index refers to j value
subprobSols[i][j] refers to optimal solution to subproblem A[i…j]
subprobSols[0][n-1] refers to the optimal sol for A[0…n-1]
Dynamic Programming Longest Palindrome
In the bottom up first what are the first cases filled out?
subprobSols[0][0] = {0}
all the way through to:
subprobSols[n-1][n-1] = {n-1}
then look
0-1
1-2
…
0-2
1-3
…
What is the run speed of longest palin buttom up
Theta of n2
Dynamic Programming Longest Palindrome
What is the overlappin subproblems property

Dynamic Programming 0-1 knapsack
What is the speed?
O(nk)
n = num of items
k = capacity
Fast, as long as k into too large
if k is O(n2) then nk is O of (n3)
Dynamic Programming 0-1 knapsack
What are the base and recursive cases?
Base Cases:
recursive cases:
Dynamic Programming 0-1 knapsack
How is the table set up?
What does i keep track of of?
What does j keep track of?
first index i keeps track of which item we are considering (starting at n down to 1)
second index j keeps track of the remaining capacity (starts at k, down to 0)
Dynamic Programming 0-1 knapsack
How do we decide what value to put in table entry?
Where is the answer located?
w(i,j) is exactly the value that we want to store in entry [i][j] of the table
The answer is in w(n,k)
we use the same formula:
w(i,j):
Dynamic Programming 0-1 knapsack
What is the table filling order, what are the base cases to fill in?
Fill the table in order
sol[0][0] is item 0 with cap 0
sol[0][1] is item 0 with cap 1
sol[1][0] best of so far with cap 0, etc
Dynamic Programming 0-1 knapsack
What is the speed of bottom up
Theta of (nk)
Dynamic Programming 0-1 knapsack
How would the solutions table be implemented (code)
capacity = k
we need a decision table that represents if that item is in the opt sol (true, false)
We use that table to build the rest.
for(int i = n-1; i>=0; i–){
if(decision[i][capacity] == true){
solution[i] = true;
capacity = capacity - I[i][0];
}else{
solution[i] = false;
}

What is the definition of Expectation of T?
Expectation of T is the sum of each probabiltiy mult by it’s lines of code.

What is a randomiszed algo?
An algorithm whose execution is determined in part by a source of random bits
In general what is the Las Vegas algo
It outputs an answer that is always correct
It’s run time depends on a randomness, but they most often run fast
What is the Monte Carlo algo?
Is an algo that always runs fast (it’s speed isn’t dependant on a random variable)
But the answer may not be correct, or may be close to correct.
What is Freivalds random algo for verifying matrix multiplications
Verifying Matrix mults
what is the run speed?

Divide and Conquer
What is merge sort’s divide, conquer and combine?
What is it’s formula and run speed?
Divide:
Partition A into two subarrays: A[0…n/2] and A[n/2+1…n-1]
Conquer:
Recursively sort each subarray using MergeSort
Combine:
Merge the two sorted subarrays into one sorted array, by repeatedly comparing the smalles from each subarray

Graphs:
What is the cost to brute force?
How fast is Prim’s?
How fast is Kruskals?
Brute : nn-2
Prim and Kruskal = O(ElogV)

Matrix Multiplication
What is the divide, conquer and combine for naive and Stressen’s?
What is the speed of naive, divide and conquer and Strassens?
Divide: Part A&B in 4 n/2-by-n/2 matrices
Conquer: recursively computer 8 matrix mults of size n/2-by-n/2
Combine: Use 4 matrix additions to computer the n/2-by-n/2 matries c11, c12,c21,c22
Base case: when A and B are 1-by-1 matrices, return A11B11

Matrix Mult
How are they multiplied?

Half-Plane Intersection
Given a convex polygon P and a half-plane h, the intersection is either:

What is the cost of half-plane brute force?
