Graphs
- Graph
- Adjacency list
- Adjacency matrix
Linked Data Structures
Linked list
desc | ||
---|---|---|
list-insert(L,x) | insert x onto the front of the linked list | |
list-delete(L,x) | delete element x from the linked list | |
list-search(L,k) | returning a pointer to the first element with key k |
Trees
Heap
Binary Heap
-
A binary heap (or heap) is defined as a binary tree with two additional constraints:
- shape property: a binary heap is a complete binary tree
- heap property:
- (max-heap) for every node other than the root, )
- (min-heap) for every node other than the root, )
- Heaps are commonly implemented with an array of length .
- In our implementation, the root of is in , so
- the last index is
- (Alternatively, the root can be in , so , , and , and the last index is )
- In our implementation, the root of is in , so
-
Theorems:
- The index of the -greatest () element in max-heap is
- (the same for -smallest element in min-heap)
- (6.3-3)todo There are at most nodes of height in any -element heap
- The index of the -greatest () element in max-heap is
procedure (max heap) | Run Time | |
---|---|---|
heapify(A, i) | (the height of is ) | |
max-heapify(A, i) | ||
build-max-heap(A) | ||
heap-maximum(A) | returns the element of with the largest key | |
heap-extract-max(A) | remove max and retrun it | |
heap-increase-key(A,i,key) | increases the value of to new value (larger or equal) | |
max-heap-insert(A,key) | insert to |
- in min-heap the procedures will be: min-heapify, build-min-heap, heap-minimum, heap-extract-min, heap-decrease-key, min-heap-insert
Binary Search Tree (BST)
-
Type of: Binary Tree
-
Sorted data structure
-
all dynamic set operations take time
-
Traversal (Inorder, preorder, and postorder) take time
-
(12.4) The expected height of a randomly built BST on distinct keys is
Red-Black Tree (RB)
-
Red-Black Tree is Binary Search Tree, which staify the Red-Black tree properties:
- Every node is either black or red
- The root is black
- Every leaf (NIL) is black
- if node red, then both of its children are black (thus, red nodes black nodes)
- For each node, all simple paths from the node to leaves have the same number of black nodes, (limiting h ???)
-
is the black-height of the node , which is the number of black nodes on any path from a node (not including) down to a leaf
-
is the black-height of a RB tree, which is the black-height of the root
-
(13.1) A red-black tree with internal nodes has height at most . (which means that it’s approximatly balanced)
-
dynamic set operations take time
Order-statistic tree
-
(Theorem 14.1) Augmenting a red-black tree - Let be a field that augments a red-black tree of nodes, and suppose that the contents of for a node can be computed using only the information in nodes , , and , including and . Then, we can maintain the values of in all nodes of during insertion and deletion without asymptotically affecting the performance of these operations.
-
order-statistic tree is RB Tree with additional node field: size.
- returns a pointer to the node containing the th smallest key in the subtree rooted at . ( (worst case))
- returns the position of in the linear order determined by an inorder tree walk of . ( (worst case))
Hash Tables
Hash function
Collision resolution
Chaining
Average | Worst | |
---|---|---|
space | ||
chained-hash-insert(T,x) | ||
chained-hash-search(T,k) | ||
chained-hash-delete(T,x) |
Open addressing
- Linear probing
- Quadratic probing
- Double hashing
Direct-address tables
operation | |
---|---|
direct-address-insert(T,k) | |
direct-address-delete(T,x) | |
direct-address-search(T,x) |