Test 1 Review
for CMPS 2200, Fall 2012
Relevant Material:
- All material from 9/4/12 until 10/2/12 (inclusive).
- This includes material covered in the lectures, and homeworks 1 - 4.
- The covered chapters in the book are 0.3 and 2.1,2,3,4,5 (not 2.6). Note that on some of the topics we covered additional details in the lectures (e.g., Master Theorem, randomized algorithms).
- Analyzing Algorithms
- Best case, worst case, and average 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 satisfies)
- 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
- 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 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 and asymptotic bound for a recursively given T(n)):
- Induction
- Prove your guess/claim using induction. [We have only covered regular strong induction, and not a particular type of big-Oh induction (sometimes called substitution method) which would allow to choose constants c and n_0.]
- Master Method
- find the value of a
and b
- compute n^(log of a
base b) 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
- Probability, Random
Variables and Expected Values
- Define the sample space
and random variables for a given problem
- Compute expected
values of your random variables using definition of
expectation and linearity of expectation
- Randomized Algorithms
- Expected runtime vs. average runtime, best-case runtime, and worst-case runtime
- Quicksort
- Runtime:
- Best case: O(n log n) [When each pivot
partitions the array into two roughly equal pieces]
- Worst case: O(n^2) [When the array is already
sorted either increasing or decresing order]
- Average Case: O(n log n)
- Sorting
- Counting Sort:
- Decision Trees:
- For a given (sorting or searching) algorithm
- Lower bound for comparison sorting (or searching) algorithms.
- Order Statistics
- Select Algorithm: to select the
i-th smallest element
- Randomized Select: Runtime
- Worst Case: O(n^2)
- Average Case/Expected Runtime: O(n)
- [Deterministic Select: Runtime O(n)]
Practice Problems from the Book:
- Chapter 0.4: Exercises 1, 2,
- Chapter 1.6: Exercise 4
- Chapter 2.7: Exercises 1, 3 (use recursion trees), 4, 5, 6, 12, 13, 15, 16, 17, 18, 19, 22, 23