Midterm Review for CMPS 2200, Fall 2015
Relevant Material:
- All material from 8/24/15 until 10/7/15 (inclusive).
- This includes material covered in the lectures, and homeworks 1 - 6.
- Analyzing Algorithms
- Best case and worst case runtimes
- Asymptotic Notation (О, Ω, Θ, ο)
- Prove by definition (find a value for c>0 and n_0 > 0
so that for all n≥n_0 the inequality is satisfied)
- f(n) belongs to O(g(n)
- f(n) belongs to Ω(g(n)
- f(n) belongs to Θ(g(n)) [prove both O and Ω]
- Prove using limit theorem
- Analyze code snippets
- Heaps
- Min-heap property, heap definition
- Using array implementation, findMin takes O(1) time, and extractMin and decreaseKey take O(log n) time
- Heapsort: Repeatedly extract min in min-heap; O(n log n) time
- Red black trees:
- Properties of binary search trees
- Properties of red black trees
- If black-height is b and the height of the tree is h, then b<=h<=2b
- h = b when all the nodes in the tree are black
- h=2b when you have red and black nodes in alternating levels
- Sample Questions:
- Justify whether a given tree is a legal red black tree / binary tree / balanced search tree
- Show rotations on a binary search tree
- Maximum and minimum number of elements in a red black tree with black height b
- B-Trees:
- A B-tree with minimum degree k >= 2 has the following properties:
- Number of keys in root: 1<= #keys <= 2k-1
- Number of keys in other nodes: k-1 <= #keys <= 2k-1
- Each node has exactly #keys stored in that node + 1 number of children
- All leaves are in the same level
- Only a root split can increase the height of a B-tree
- Sample Questions:
- For a given tree justify if it is a legal B-tree
- For a given set of numbers come up with all possible legal B-trees
- Maximum and minimum number of keys possible to store in a B-tree
- Insertion in a B-tree (use preemptive splitting, and show node split if needed)
- Recursion:
- Divide & Conquer
- You can call an algorithm Divide and Conquer only if the size of
subproblems can be written as n/b where b>1
- Regular Recursion
- Subproblems can be of size n-1, n-2, n-3 etc.
- Recursive algorithms and thinking
- Find a recursive solution to a problem; recursive pseudocode
- Recursive squaring, multiplying n-bit integers, Strassen's algorithm
- Runtime recurrence
- Find the runtime recurrence for a recursive algorithm given in pseudocode
- Solving Recurrences: Solve a runtime recurrence (i.e., find an upper bound for a recursively defined T(n)):
- Recursion Tree: Find a guess what a (runtime) recurrence could solve to
using recursion trees
- Given T(n) = aT(n/b) + f(n)
- a = #of subproblems = #of children at each node
- n/b = subproblem size
- Height of the tree = log_b (n) [log of n base b]
- Master Method
- Find the value of a and b
- Compute n^(log_b (a) and compare with O(f(n))
- Please clearly write which case it is and give the values for epsilon, k, and c:
- For case 1: Give the value of epsilon>0
- For case 2: Give the value of k>=0
- For case 3: Give the value of epsilon>0, check the regularity condition and give the value of c<1
- Dynamic Programming (DP):
- An algorithm design technique where
- each subproblem is solved only once and the solution is stored in a dynamic programming table (DP table),
- and this stored value/solution will be used later whenever needed.
- This approach applies only if the problem has the following two properties:
- Optimal substructure (recursion)
- Overlapping subproblems
- Sample Questions:
- Understand a given recursive solution, and analyze the time and space needed for a brute-force implementation of the recursion.
- Develop a recursive solution for a problem similar to problems covered in class or on the homework.
- Design a DP algorithm using a given recurrence and either of the following approaches
- Bottom-up: Use one or more nested loops and fill the whole DP table bottom-up.
- Memoization: Use recursion and fill only the cells of the DP table which are needed during the recursion, in the order determined by the recursion.
- Analyze time and space of your DP algorithm.
- Give an algorithm to fill the DP table for a given recursive solution and compute the solution from it.
Practice Problems from the Book:
- Chapter 0: Exercises 1, 2, 4,
- Chapter 1: Exercises 3, 4, 7,
- Chapter 2: Exercises 1, 3 (use recursion trees), 4, 5, 6, 12, 13, 17, 19, 23, 27, 29, 32
- Chapter 6: 1-19, 22, 24-29