



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of questions and answers related to the knapsack problem and various algorithm analysis techniques. It covers topics such as the dimensions of arrays used in solving the knapsack problem with and without repetition, recurrence relations, base cases, and running times. Additionally, it includes questions on matrix multiplication, longest increasing subsequence (lis), longest common subsequence (lcs), edit distance, floyd-warshall, bellman-ford, and runtime complexities of various algorithms like binary search, mergesort, and fft. The document also touches on logarithmic properties and master's theorem, offering a concise review of essential concepts in algorithm design and analysis.
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




What are the dimensions of the array for solving the knapsack problem WITHOUT repetition? - ANSWER - 2 - D array What is the recurrence for knapsack w/o repetition? - ANSWER - K(i,b) = max((vi + K(i-1,bi- wi)),K(i-1,b) if wi < b) K(i,b) = K(i-1,b) otherwise What are the base cases for knapsack w/o repetion? - ANSWER - K(0,b) = 0 & K(i,0) = 0 which is when we have no objects and no knapsack, respectively What is the running time of the knapsack w/o repetition algorithm? - ANSWER - It is pseudopolynomial O(nB) What are the dimensions of the array for solving the knapsack problem WITH repetition? - ANSWER - 1 - D array What is the recurrence for knapsack w/ repetition? - ANSWER - K(b) = max(vi + K(b-wi)) for all items i with a weight less than or equal to current capacity b What is the running time of the knapsack w/ repetition? - ANSWER - O(Bn) What is the time complexity for multiplying two matrices A (dimensions n x m) and B (dimensions m x k) - ANSWER - O(nmk) If we have n matrices, A1, A2... An how can we define each of their sizes? - ANSWER - mi-1 x mi since the inner dimensions of a matrix product must match Whats the most likely base algorithm to use if problem only has a single array? - ANSWER - LIS
What is the most likely algorithm if problem is comparing to iself - ANSWER - LIS What is the most likely alg if problem only looks back one elemnt at a time (not a window, or a bag) - ANSWER - LIS What are the two most common LIS variations? - ANSWER - O(n) lookback O(1) lookback What is most likely alg if problem is comparing between two arrays? - ANSWER - LCS What is most likely alg if problem is looking for something in common? - ANSWER - LCS Describe the process for LCS (substring variation) - ANSWER - Add 1 to L(i-1,j-1) and set to 0 otherwise. Solution is max(L) Describe the process for LCS (subsequence variation) - ANSWER - If ending characters are same: L(i-1,j-1) + 1 If ending characters are different: max{ L(i-1,j), L(i,j-1) } Solution is L(n,m) or L(n,n) What is most likely alg if problem is looking to minimize differences? - ANSWER - Edit Distance What is the most likely alg if the problem assigns some penalty to differences? - ANSWER - Edit Distance What is the most likely alg if problem assigns some points to matches? - ANSWER - Edit Distance
Runtime complexity of FFT - ANSWER - O(nlogn) Runtime complexity of Fast select (median of medians) - ANSWER - O(n) Runtime complexity of bellman ford - ANSWER - O(|V||E|) Runtime complexity of Floyd-Warshall - ANSWER - O(|V|^3) Runtime complexity of Fast Multiply (Integers) - ANSWER - O(n^log3) log(xy) =? - ANSWER - log(x) + log(y) log(x/y) =? - ANSWER - log(x) - log(y) logb(x) =? - ANSWER - loga(x)/loga(b) x^log(y) =? - ANSWER - y^log(x) Masters Theorem - (f(n) = n^logb(a)-e - ANSWER - Case 1 - O(n^logb(a)) Masters Theorem - (fn) = n^logb(a) - ANSWER - Case 2 - O(n^logb(a)logn) Masters Theorem - (fn) = n^logb(a) + e - ANSWER - Case 3 - O(f(n)) What is the running time for Longest Increasing Subsequence (LIS) - ANSWER - O(n^2) What is the recurrence for Longest Increasing Subsequence (LIS)? - ANSWER - L(i) = 1 + max{ L(j) | xj < xi} This reads as the ANSWER to index I is 1 + the maximum over all j's between 1 and i where xj is less than xi
What is the recurrence for Longest Common Subsequence (LCS) - ANSWER - L(i,j) = 1 + L(i- 1, j-1) if xi = yj L(i,j) = max(L(i-1,j),L(i,j-1)) otherwise What is the running time for Longest Common Subsequence (LCS) - ANSWER - O(n^2)