Midterm 1:
Summation:


Algorithm Approaches
Divide and Conquer:
Divide - The problem into subproblems that are smaller instances of the same problem
Conquer - Solve the smallest instances recursively (calling the same function)
- If instance is small enough, solve directly (base case)
Combine - Combine the solution to smaller instances into a final answer
Recursion?
3 Methods of Solving Recurrence
Recursive - A function that calls itself
You can tell which will be the biggest contributor via Master Theorem, or inspection
Methods:
- Recurrence Tree Method (Relevant Lecture)
- Find the work done at each level
- Find the depth / number of levels
- Do a sigma sum, and calculate the work done
- You now have work done
T(n) = 2T(n/2) + O(1)
Work:(2)
Depth:
Total Work:
- Substitution
- Make a guess about the runtime
- Prove that it holds true for your guess, if not make a new guess
T(n) = T(n/6) + T(2n/6) + O(n)
Guess that T(n) = O(n)
This would mean that
T(k) = T(k/6) + T(2k/6) + O(k)
by IH we can say that this is less than or equal to:
= c(k/6) + c(2k/6) + akck
c/2 + ac
ac/2
2ac
Our guess holds true, as c can be set to 2a and be true.
- Master Theorem
https://www.youtube.com/watch?v=2y0HQGd1-nA
3 Cases: : The tree/subproblems win - Solution is
- Solution is
: They are both even - Solution is
- Solution is
: The initial work wins - Solution is
- Solution is
Big __
Big-O: An upper bound as n goes to infinity. Saying that
Big-
Big-
Formally:
Proving Big __
For Big O and Big Omega:
Can do the same but proving less than or equal to to prove big Omega
For Big Theta:
Prove that a function is BOTH big O and big Omega of some function. The constants
Limit lemma:
If
3 Cases:
L=0 => f(n) = O(g(n))
L=
L= some C => f(n)=
Big-O of Operations:
Merge sort: