Back to HomeMidterm II Review
- 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:
- Mergesort
- Insertion sort
- 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:
- 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
- Insertion (show rotations if needed)
- 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 same level
- only 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)
- Dynamic Programming (DP):
- It is a problem solving technique (or 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 can be used only if the problem has
the following two
properties:
- Overlapping Subproblems
- Optimal Substructure
- Sample Questions:
- Understand a given recurrence, and
analyze the time and space needed for a
brute-force implementation of the recurrence
- 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 ( Example:
Homework 8, Problem 3(a))
- Memoization: this approach uses
recursion and fills only the cells of the DP table which are needed (
Example: Homework 8, Problem 3(c))
- analyze time and space of your DP algorithm
- Fill the DP Table for a given input and compute the
solution from it
- Modify a well-known
DP algorithm (like LCS, Fibonacci, etc.) or the one you develop or a given
one, so that it take less space or time
Greedy Algorithms
- Greedy Strategies:
- repeatedly identify the decision
to be made (recursion)
- make a locally optimal choice for each decision
- Greedy doesn't always work.
- Sample Questions:
- Short questions or true/false
about the concepts
- Come up with a greedy solution to a
problem or with a counter-example why a greedy solution
does not work.