Midterm Review for CMPS 2200, Fall 2017

Relevant Material:

  1. Analyzing Algorithms [Ch. 0 Dasgupta, ch. 2 CLRS]
    • Best case and worst case runtimes
    • Not on the test: Loop invariants
  2. Asymptotic Notation (О, Ω, Θ, ο) [Ch. 0 Dasgupta, ch. 3 CLRS]
    • 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
  3. Heaps [Ch. 4.5.2 Dasgupta, ch. 6 CLRS]
    • Max-heap property, heap definition
    • Using array implementation, findMax takes O(1) time, and extractMax takes O(log n) time
    • Heapsort: Repeatedly extract max in max-heap; O(n log n) time
  4. Red-black trees: [Ch. 13 CLRS]
    • 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
    • Not on the test: In-depth knowledge of the different cases of the insertion procedure
    • Sample Questions:
      • Justify whether a given tree is a legal binary search tree or a legal red black tree
      • Show rotations on a binary search tree
      • Maximum and minimum number of elements in a red black tree with black height b
  5. B-Trees: [Ch. 18 CLRS]
    • 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:
      • Justify whether a given tree 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)
  6. Recursion: [Ch. 2 Dasgtupa, Ch. 4 CLRS]
    • 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
      • There are other recursive algorithms, that are not divide-and-conquer. The subproblems for these problems might have size n-1, n-2, n-3 etc.
    • Recursive algorithms and thinking
      • Find a recursive solution to a problem; recursive pseudocode
      • Mergesort, powering a number
      • Not on the test: Convex hull computation
    • Runtime recurrences
      • Find the runtime recurrence for a recursive algorithm given in pseudocode
  7. Solving Recurrences [Ch. 2 Dasgtupa, Ch. 4 CLRS]: 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]
    • Big-Oh Induction
      • Prove your guess/claim using big-Oh induction (also called substitution method). Prove both the base case and the inductive step, and find constants c and n_0 during the proof.

Practice Problems from the books:

  1. Analyzing Algorithms:
    • CLRS, page 22: 2.1-2, 2.1-3
  2. Asymptotic notation:
    • Dasgupta, chapter 0: Exercises 1, 2,
    • Dasgupta, chapter 2: Exercises 3 (use recursion trees), 4, 5, 12, 13, 17, 19, 23,
    • CLRS, page 52: 3.1-1,4
    • CLRS, page 61: 3-3 (some are quite hard)
  3. Heaps:
    • CLRS, page 153: all exercises
    • CLRS, page 156: 6.2-3,4
    • CLRS, page 160: 6.4-3
  4. Red-black trees:
    • CLRS, page 289: 12.1-1,2
    • CLRS, page 312: 13.1-6
    • CLRS, page 314: 13.2-3
    • CLRS, page 322: 13.3-3,5
  5. B-trees:
    • CLRS, page 490: 18.1-1,2,3,4,5
    • CLRS, page 497: 18.2-1,3
  6. and 7. Divide-and-conquer and runtime recurrences:
    • CLRS, page 39: 2.3-3,4,5,6
    • CLRS, page 87: all exercises
    • CLRS, page 92: all exercises
    • CLRS, page 107: Practice the recursion tree method and big-Oh induction on the problems shown in 4-1,3. Note that the big-Oh induction will not work in all cases (there is a more complicated way to handle this, which we have not covered in class)