140 likes | 166 Views
COMP171 Spring 2009. Course Review. Elementary Data Structures. Linked lists Types : singular, doubly, circular Operations : insert, find, delete O( N ) Stack ADT (array or linked-list) First-in-Last-out Operations : push, pop Queue ADT (array or linked-list) First-in-First-out
E N D
COMP171 Spring 2009 Course Review
Elementary Data Structures • Linked lists • Types: singular, doubly, circular • Operations: insert, find, delete O(N) • Stack ADT (array or linked-list) • First-in-Last-out • Operations: push, pop • Queue ADT (array or linked-list) • First-in-First-out • Operations: enqueue, dequeue • Priority queue (heap) • Heap-orderproperty • Operations: insert and deleteMin (both O(log N) using array)
Analysis of Algorithms • Worst case analysis • time and memory space • depends on the input (size, special features) and algorithms • growth rate of the functions • Asymptotic notations • O(.): upper bound, “at most”, worst case, ≤ • Ω(.): lower bound, “at least”, best case,≥ • Θ(.): tight bound, O(.) && Ω(.), asymptotically “≈” growth rate
Other Sorting Algorithms • Theorem: Any comparison based sorting algorithm takes Ω(n logn) comparisons to sort a list of ndistinct elements. • Non-comparison sorting • Rely on some special features of the input • Counting sort: O(N + Range) • Radix sort: O(N × #digits)
Overview of the Forrest • Binary Trees • Binary Search Trees • AVL trees • M-ary Trees • B+-Trees • Terms: • root, leaves, child & parent, siblings, internal nodes, • height, paths & length, depth, • subtrees • Main theme: search, insertion, deletion.
Binary Search Trees • Traversal • Pre-order, in-order, post-order • Average depth O(log N), max depth O(N), • Operations: • Search, findMin, findMax • Insertion • Deletion: 3 cases, recursive • All takes O(height of the tree).
AVL Trees • Balanced BST • Height of an AVL tree is O(log N). • Search O(log N) • Insertion: 2 types of rebalancing O(log N) • Trace from the new node to the root, locate the unbalanced node, and at most one rotation. • Single rotation for “outside” insertion • Double rotation for “inside” insertion • Deletion O(log N) • Trace the deletion path, and more than one node may need rotation.
B+-Trees • M-ary trees • The root is either a leaf or has 2 to M children (1 to M-1 keys). • Each internal node, except the root, has between M/2 and M children ( M/2 - 1 and M - 1 keys). • Each leaf has between L/2 and L keys and corresponding data items. • The data items are stored at leaves • Search • Insertion: always insert to a leaf • Possibly splitting leaf (and internal nodes) • Update the key in a internal node if necessary • Deletion • “Borrow” a key from your siblings • Merge two leaves (or internal nodes) – opposite to splitting
Graph Essentials • Graph = Vertices + Edges • Representation • Adjacency matrix: O(N2) space, O(1) access time • Adjacency list: O(M+N) space, O(N) access time • Keywords • subgraph, tree, acyclic graph • path, length, cycle, simple • directed, undirected • incident, degree, indegree / outdegree • connected components
Graph Traversal: BFS • Connectivity and shortest path (from source) • Time: O(M+N) • Use visited table, predecessor list, and distance table • BFS tree
Graph Traversal: DFS • Connectivity and cycle detection • Time: O(M+N) • Recursive function • DFS tree
Topological Sort • Topological ordering on DAG and connectivity • Time: O(M+N) • Repeatedly remove zero-degreed vertices and the outgoing arcs • Linear ordering
Hashing • Hashing is a function that maps a key (K) into an entry in a table (hash table), T[h(K)]. It only supports operations Find, insertion, deletion • The hashing function should be • Computationally fast, and efficient with O(1) complexity • Minimize the collisions, when T[h(K1)] = T[h)K2)] and K1 and K2 are two distinctive keys • Collision Resolution 1: Separate chaining • Collision Resolution 2: Open Addressing • Linear Probing • Quadratic Probing • Double hashing