Recursion
What is Akra-Bazzi Theorem?
A generalization of Master Theorem, that can deal with cases where the subproblems are different sizes
What is the most common use for backtracking?
Constraint satisfaction problems
What is the advantage of using Quick Sort?
When implemented well, quick sort can be two or three times faster than its predecessors and competitors such as merge sort
What are the three main differences between divide and conquer problems and backtracking problems?
1. D&C usually have a sole solution, where backtracking has an unknown number of solutions 2. Each step in a D&C is indispensable to the final solution, while many steps in a backtracking problem might not be useful to the final solution 3. D&C has a clear and defined path, while backtracking problems one does not know in advance the exact path to the solution
What are the three general steps to a divide and conquer algorithm?
1. Divide: Divide the problem into subproblems 2. Conquer: Solve each problem recursively 3. Combine: Combine the results of each subproblem
What is the use of Master Theorem?
Quickly calculate the time complexity of many recursion algorithms
What are the steps of the merge sort top down algorithm?
1. Select a pivot index, usually the mid point of the array 2. Merge sort the left half 3. Merge sort the right half 4. Merge the lists together a. Create a return array the combined size of the lists b. Create a left, right, and return pointer c. While the left and right pointers are both less than their lists' lengths, add the smaller element to the return array and increment the appropriate pointers d. Append the remaining elements from the list that the pointer has not yet reached the end for
What is the disadvantage of Quick Sort?
It is not a stable sort
What is the limitation of Master Theorem and the answer to the limitation?
It only applies to cases where the subproblems are of equal size Akra-Bazzi Theorem
What is the formula for Master Theorem and what does each part represent?
T(n) = a * T(n/b) + f(n) - f(n) is the time complexity it takes to dive the problems into subproblems and then combine them: f(n) = O(n^d) and d >= 0 - b = number of subproblems - a = number of recursive calls on the subproblems
What are the three cases for the Master Theorem?
1. a > b^d then O(n^(logb(a))) 2. a = b^d then O(n^d * logn) 3. a < b^d then O(n^d)
What are the the general steps to merge sort?
1. Divide the given unsorted list into several sublists (Divide) 2. Sort each of the sublists recursively (Conquer) 3. Merge the sorted sublists (Combine)
What are the complexities of merge sort?
Time: O(nlogn) Space: O(n)
What are the steps to the Quick Sort algorithm?
1. Select a value from the list called the pivot 2. Divide the list into sublists, where one contains all the elements less than the pivot and the other contains all the elements greater than or equal to the pivot (Partitioning) a. Move the pivot to the last element of the merge space b. Set a pointer for the nextSwap and the currentElement starting at the first element of the merge space c. Loop through all the elements, if the current element is less than the pivot, swap it with the nextSwap and increment nextSwap 3. Recursively sort the two sublists 4. Concatenate the two sublists to obtain the final sorted lists
What is the definition of backtracking?
A general algorithm for finding all (or some) solutions to computational problems, which incrementally builds candidates to the solution and abandons candidates ("backtracks") as soon as it determines the candidate cannot lead to valid solution
What is the idea behind the merge sort bottom-up approach?
Divide the list into sublists of a single element at the beginning. Each of the sublists is then already sorted. Then from this point on, we merge the sublists two at a time until a single list remains
What are the complexities of Quick Sort?
Time: Worst - O(n^2), Average - O(nlogn) Space: O(1)
What is the definition of divide and conquer?
Works by recursively breaking the problem down into two or more subproblems of the same or related type until these subproblems become simple enough to be solved directly. Then combines the results of subproblems to form the final solution