n21 Final Review
n21 Final Review
REVIEW
EECS 2101
2
Algorithm Analysis
• Given an algorithm, compute its running time in terms of O, , and
(if any).
• Usually the big-Oh running time is enough.
• Given f(n) = 5n + 10, show that f(n) is O(n).
• Find c and n0
•If the exact number of iterations of some loop is not known, “open”
the loops and count the total number of iterations (as in Assignment
2).
4
Recursion
Know how to write recursive functions/methods:
•Recursive call
• Adjusting recursive parameter(s) for each call
•Base case(s)
insert O( ) O( ) O( ) O( )
delete O( ) O( ) O( ) O( )
9
Trees
Definitions, terminologies
Traversal algorithms and applications
• Preorder
• Postorder
Computing depth and height of a tree or node.
Assignment 5
11
Binary Trees
• Linked structure implementation
• Array implementation
• Traversal algorithms
• Preorder
• Postorder
• Inorder
• Properties: relationships between n, i, e, h.
• Definitions:
• complete binary tree
• full binary tree
12
B A D
A D
C E C E
12
13
search
insert
delete
findMin
findMax
18
Heaps
• Properties
• Array implementation
• Insert
• upheap percolation
• Delete
• downheap percolation
• Running time
Heap Sort
Using a temp heap T In-place sorting
buildHeap
• Bottom-up heap construction runs in O(n) time.
• Bottom-up heap construction is faster than n successive insertions, which
take O(nlogn).
speeds up the first phase of heap-sort.
22
Sorting Algorithms
• Insertion sort
• Merge sort
• Quick sort
• Heap sort
• Lower bound of sorting algorithms
• O(NlogN)
• When to use which sorting algorithm?
23
Hashing
• Table size (a prime number) Collision handling
• Hash functions •Separate chaining
• Hash codes: •Probing (open addressing)
• Memory address
• Linear probing
• Integer cast
• Component sum • Quadratic probing
• Polynomial accumulation • Double hashing
• z = 33, 37, 39, 41 (English dictionary)
• Compression functions:
• division (modulo)
•Probing: 3 types of cells (null, in
• MAD use, defunct)
24
Graphs
• Definitions (terminology) • Running time of graph methods
• Properties (with respect to V and E) • Graph traversal algorithms
• Data structures • BFS
• Adjacency matrix • DFS
• Adjacency lists • Applications of BFS and DFS
• Assignment 6
26
After Exam
• There will be office hours for students to review their exam.
• Check eClass and email for time and date