Test 1 Review
for CS 5633, Spring 2012
Relevant Material:
- All material from 1/17/12 until 2/9/12 (inclusive)
- This includes material covered in the lectures, and homeworks 1 - 4
- Analyzing Algorithms
- Best case, worst case, and average case runtimes
- Loop invariants
- 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
-
Fibonacci, recursive squaring, Strassen's algorithm
- Runtime recurrence
-
Find the runtime recurrence for a recursive algorithm given in pseudo-cde
- 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 Recurrence: Solve a runtime recurrence (i.e., find and asymptotic bound for a recursively given T(n)):
- Big-Oh induction (= substitution method)
- you will have a guess/claim
- state your inductive
hypothesis for all k<n
- replace k with a
value[the size of subproblem in the right hand side of
recurrence] < n
- plugin the value you
got in previous step into your recurrence
- find out your desired
and residual part
- residual part must
be<0,
so you will end up with a condition most likely on c
- Verify if it works for
your base case
- select a value of c(which
satisfies the base case and the condition you got from residual<0)
and n_0(base case value of n)
- 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 (for case II) and check regularity condition
and give the value of c if it is case III
- Probability, Random
variables and Expected values
- Define Sample Space
and Random Variables for given problem
- Compute expected
values of your random variables using definition of
expectation/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) [Randomized
runtime analysis will not be needed]
- Sample Questions:
- For a given Sequence of numbers what will be the runtime when
Quicksort, Radixsort or
Countingsort is used?
- Show different steps (pivot, and the partitions) of sorting an
array using Quicksort.
- Deterministic Quicksort
- Sorting
- Radix Sort:
- Counting Sort:
- Decision Trees:
- For a given (sorting) algorithm
- 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: