Course Review for Finals Cpt S 223 Fall 2008 1
Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e., space and time efficiency 2
Math Review Floors, ceilings, exponents and logarithms: Definitions and manipulations Series: Definitions, manipulations, arithmetic and geometric series closed form Proofs: Know definition, components, and how to use the following Proof by induction Proof by counterexample Proof by contradiction Recursion Know definition and rules Analyze running time of recursive algorithm Tail recursion removal 3
C++ Review Know definitions and how to use the following Class, method, encapsulation Constructor, destructor, accessor, mutator Reference variable (&x) and call by reference Copy constructor, operator overloading, operator= Templates STL for different data structures 4
Algorithmic Analysis Why analyze an algorithm? What do we measure and how do we measure it? Line-by-line analysis Best-case, worst-case and average-case analysis Rate of growth: Definitions and notation (O, Ω, Θ, o, w) 5
Abstract Data Types Lists Operations: Insert, Delete, Search Implementations: vectors, singly-linked lists, double-linked lists, sentinels Analysis of operations for each implementation Stacks (LIFO) Operations: Push, Pop, Top Implementations: linked-list, vector Analysis of operations for each implementation Queues (FIFO) Operations: Enqueue, dequeue Implementations: linked-list, vector Analysis of operations for each implementation Standard Template Library (STL) Use of vector, list, stack and queue template classes Use of iterators Know all the tradeoffs (in time & space) between all these data structures 6
Trees (in memory) Definitions: root, leaf, child, parent, ancestor, descendant, path, height, depth Binary tree: Definition, traversals Storing/representation: 1. All children: use array or list 2. Store pointers to only Leftmost child and right sibling Tree traversals Inorder, postorder and preorder 7
Search Trees Binary search tree (BST) Definition Operations: Insert, Delete, Search, FindMin, FindMax, traversals Know how to perform these on a BST and show resulting BST Know worst-case and average-case analysis of performance Balanced BST (AVL trees) Definition Operations: Rotations & Cases, Insert, Lazy Delete, Search, FindMin, FindMax Know how to perform these on an AVL tree and show resulting AVL tree Know worst-case performance STL set and map classes Differences How to use them 8
Disk-based Search Trees B-trees Definition and properties Input parameters: B, D, K M and L, and how to choose them Operations: Insert, Delete, Search Know how to perform these on a B-tree and show resulting B-tree Know worst-case performance Know how to calculate height of a B-tree 9
Priority Queues Binary heap, Binomial heaps Definitions: Binary heap Structure property: complete binary tree except the last level (filled breadth-first left to right) Heap order property Min heap : each node s value is less than or equal to its children Binomial heap Structure property: A forest of binomial trees (similar to binary representation) Heap order property: Min heap: within each binomial tree, same heap order like in binary heap 10
Implementation Binary heap Tree structure can be implemented as an array Where nodes are stored in breadth-first order Children of node at A[i] are at: A[2i] and A[2i+1] Binomial heap Array of pointers to each binomial tree log n binomial tree pointers 11
Run-times for each heap operation Two main techniques: percolateup and percolatedown Insert DeleteMin Merge Binary heap Binomial Heap O(1) - amortized O(1) O(log n) O(log n) Other operations: deletemax() decreasekey(p,v), increasekey(p,v) remove(p) O(n) O(log n) 12
Union-Find data structure Purpose: Compute equivalence class Equivalence class: Maximal subsets defined by equivalence relation Disjoint subsets Union-find Supports two operations on disjoint sets: Union(a,b) Find(a) Array implementation 13
Steps in the Union (x, y) 1. EqClass x = Find (x) 2. EqClass y = Find (y) 3. EqClass xy = EqClass 1 U EqClass 1 Initially, put each element in a set of its own FOR EACH element pair (a,b): Check [a R b = true] IF a R b THEN Union(a,b) 14
Heuristics & their Gains Arbitrary Union, Simple Find Union-by-size, Simple Find Union-by-rank, Simple Find Arbitrary Union, Path compression Find Union-by-rank, Path compression Find Worst-case run-time for m operations O(m n) O(m log n) O(m log n) O(m log n) Extremely slow Growing function O(m Inv.Ackermann(m,n)) = O(m log*n) 15
Hashing Hash functions (purpose: string to integer) Choice of a good hash functions Reduce chance of collision Relatively smaller key value Does not need huge hash table size Hash table size should be a prime Load factor Know algorithms & analysis for the following Collision resolution by chaining Collision resolution by open-addressing Linear probing, quadratic probing Double hashing Rehashing Extensible hashing 16
Sorting Know algorithms & analysis of all sort methods mentioned below Insertion sort Merge sort Heap sort Quick sort Lower bound for sorting Counting sort Bucket sort 17
Comparison Sorting Sort Worst Case Average Case Best Case Comments InsertionSort Θ(N 2 ) Θ(N 2 ) Θ(N) Fast for small N MergeSort Θ(N log N) Θ(N log N) Θ(N log N) Requires memory HeapSort Θ(N log N) Θ(N log N) Θ(N log N) Large constants QuickSort Θ(N 2 ) Θ(N log N) Θ(N log N) Small constants 18 18
Graphs Definitions Simple graph, directed graph, weighted graph Path, cycle Representation as adjacency matrix and adjacency list Topological sort: Algorithm and running time 19
Graphs Shortest paths Problem definition Single-source Negative weights and negative-weight cycles Know running times for different graph cases: weighted vs. unweighted, directed vs. undirected Unweighted shortest path Dijkstra s algorithm, and why it works Graphs with negative edge costs Acyclic graphs and critical path analysis 20
Graphs Minimum spanning trees Problem definition Prim s algorithm (know algorithm and running time) Kruskal s algorithm (know algorithm and running time) Applications 21
Specialized Data Structures Spatial data structures Quad-tree for 2D Oct-tree for 3D Uncompressed vs. compressed (same as compacted ) Know how to draw compacted trees for 2D input String data structures Lookup table (exponential space) PATRICIA tree (linear space) Suffix tree (linear space) Know how to draw a suffix tree for a given input Know algorithm and complexity for pattern matching (find P in T) 22
Final Exam Tuesday 8am -10am In class Closed book, closed notes Comprehensive 23
Thank You & Good Luck! COURSE EVALUATIONS!! 24