Lecture Notes for CS 512, Algorithm Design
21 September 1999
These are provisional lecture notes, expect changes.
- data structures
- a set of operations - adt
- behavior - insert, fetch, delete, initialize
- cost
- sometimes storage or representation - cost
- element
- a generic object - something of type t
- operations - equality, total ordering
- array - vector, matrix
- mapping from a range of integers to elements of type t
- constant cost operators; fixed size
- directly supported by compilers
- record - struct
- mapping from tags to elements of type t1 + t2 + t3 + ...
- constant cost operators; fixed size
- directly supported by compilers
- linked lists
- dynamic data structure
- generally, type node = rec ( next : pointer to node ; data : t)
- non-constant access
- tree - connected dag
- root, parent, child, sibling, ancestor, descendent, leaf, internal,
frontier, fringe, ...
- binary trees, ternary trees, quad trees, oct-trees, k-ary trees
- degenerate, unbalanced - worst cases
- lots of mathematics associated with trees - how many edges in a tree
with n nodes?
- heap - binary tree with data
- heap property - parent's data is at least its childrens' data;
priority queue
- insert - add at the bottom and bubble up
- remove - move bottom to top and bubble down
- trees are complete O(log|n|) at best
- array implementation - a[i], a[2i], a[2i + 1]
- binary search tree - dictionary
- parent data fits between left and right child's data
- search - walk down the tree
- insert - walk down to a leaf, then insert
- delete - walk to the predecessor or successor, swap, and delete
- worst case O(n), average case O(log n)
- avl tree
- do more work when inserting and deleting to keep the tree nice
- avl property - subtree heights differ by at most one
- rotations - single and double
- hashing
- arrays have good put and get, not good searching
- also, identifying an index value with an item
- hash function - turn an item into an index value
- collisions
- hash functions - items to integers; mods and primes
- dealing with collisions - open or separate chaining; linear probing.
- graphs
- representation - adjacency matrix, adjacency list; node-edge list.
This page last modified on 23 September 1999.