Test Review
for CMPS 2200, Fall 2014
Relevant Material:
- All material from 8/25/14 until 10/2/14 (inclusive).
- This includes material covered in the lectures, and homeworks 1 - 5.
- 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 insert 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
- Rotations in binary trees (not necessarily red-black trees)
- No insertion
- Maximum and minimum number of elements in a red black tree with
black height b
- B-Trees:
- A B-tree with
minimum dregree k >= 2 has following properties
- Number of keys in root: 1<= #keys <= 2k-1
- Number of keys in other nodes:
k-1 <=
#keys <= 2k-1
- Each node will have exactly #keys stored in that node + 1
number of children
- All leaves will be 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 (show node split if needed; remember to pre-emptively split on the way down to a leaf when inserting a node)
- 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
- Recursion Tree: Find a guess what a (runtime) recurrence could solve to
using the recursion tree method
- 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]
- Solving Recurrences: Solve a runtime recurrence (i.e., find an upper bound for a recursively defined T(n)):
- 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 the value of epsilon(for case I and
III), k>=0 (for case II) and check regularity condition
and give the value of c<1 if it is case III
- 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:
- overlapping subproblems
- optimal substructure
- 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: this approach uses
a loop and fills the whole DP table bottom-up.
- 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
- Greedy Algorithms
- Greedy Strategies:
- repeatedly identify the decision
to be made (recursion)
- make a locally optimal choice for each decision
- Greedy does not always work.
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, 25, 27, 29, 32
- Chapter 6: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 22, 24, 25, 26, 27, 28, 29