120 likes | 132 Views
This lecture provides a review of key topics for the upcoming midterm, including math background, algorithm analysis, lists, stacks, queues, trees, search trees, priority queues, and hashing. Study materials and practice problems are provided.
E N D
CSE 326: Data Structures: Midterm Review Lecture 15: Monday, Feb 10, 2003
The Midterm Mechanics • Wednesday, 2/12/2003, 1:30-2:20 (50’) • We may start a few minutes early so you have > 50’ • Chapters 1-6 in the textbook • Closed book, closed notes, except: • You may bring one 8 ½” x 11” sheet of handwritten notes • Bring pens and/or pencils
The Midterm Practice: • Read the book, the lecture notes, review the homeworks • Practice midterm and solutions are on the website • Our midterm will be a bit more challenging • Make sure you sleep well the night before • Enjoy it ! We have fun questions
Midterm Review:Math Background • Big-Oh, big-omega, and theta notations: • T(n) = O(f(n)) if there exists c, n0 s.t. forall n > n0, T(n) < c f(n) • Should we have n n0, and T(n) c f(n) instead ? • O(f(n)) means “less than or equal to” f(n) • (f(n)) means “greater than or equal to” f(n) • (f(n)) means “same as” f(n)
Summations for (i=1; i<=n; i++) for (j=1; j<=i; j++) print “hello” Summations are easy...
Recurrences f(n) = f(n-1) + n O(n2) f(n) = f(n-1) + 1 O(n) f(n) = 2f(n-1)+1 O(2n) f(n) = 2f(n/2) + 1 O(n) ...recurrencesare hard ! f(n) = 2f(n/2) + n O(n log n) f(n) = f(n/2) + 1 O(log n) f(n) = f(n/5) + f(3n/5) + n O(n) f(n) = f(n-1) + f(n-2) O(n)
Algorithm Analysis • T(n) = running time for inputs of “size” n • The “size” does not tell us everything about the input; hence: • Worst case T(n) • Average case T(n) • Best case T(n) • Analyze the algorithm: • Find f(n) s.t. T(n) = O(f(n)) • Find f(n) s.t. T(n) = (f(n)) • Need to pick f(n) to be a simple function • Amortized analysis !
List, Stacks, Queues • Lists: insert, find, delete • Singly-linked lists with header node • Doubly-linked lists and circular lists • Runtime and space needed for array-based v.s. pointer based • Stacks: push, pop • Pointer v.s. array implementations • Use of stacks in balancing symbols (recall the homework) • Queues: equene, dequeue • Array-based v.s. list based implementations
Trees • Terminology: • Root, children, parent, path, height, depth, ... • Preorder, postorder, inorder traversal of a tree • Can do recursively, or with a stack, or with pointers to parents
Search Trees • BST • Definition • Find, insert, delete • AVL trees • Definition, running times • Know the rotation cases (we wont ask you to write the code, but may ask you to show on an example) • Splay trees • Definition, running times • B-trees
Priority queues: binary heaps • Definition, implementation • Main operations: • findMin, insert, deleteMin • Other operations: • decreaseKey, increaseKey • Binomial heaps: merge • No need to know details of leftist or skew heaps
Hashing • Know how hash functions work: • Hash(k) = k mod TableSize • TableSize is chosen to be a prime, when the keys are integers • Collisions: • Chaining: colliding values linked list • Open addressing: works when table is not very full. Linear probing, quadratic probing, double hashing • Extensible hash tables That’s all, folks ! See you on Wednesday