Algorithms and Data Structures 2
Module 1: Advanced Tree Structures
1.1 Height-Balanced Trees (AVL & B-Trees)
A tree's efficiency relies on maintaining a minimized height. For a binary tree of nodes and height :
- Minimum internal nodes: (max )
- External nodes: (max )
- Height bounds:
Average access complexity is logarithmic, approximated by:
AVL Trees:
Binary search trees where the height of each internal node’s children differs by at most 1. The upper limit is derived from Fibonacci trees, where the minimum number of nodes for a given height is defined by:
Leading to the height bound:
B-Trees:
Multi-path trees where every non-leaf node (except the root) has children between and (where ). This self-balancing mechanism guarantees access, insertion, and deletion in time.
1.2 Weight-Balanced Search Trees (BB)
Weight-balanced trees tolerate structural deviation measured by the ratio of node weights. The root balance for a tree with a left subtree of size and total nodes is:
A tree is weight-balanced if for each subtree :
Rebalancing via rotation is guaranteed if .
1.3 Splay Trees and Treaps
Splay Trees: Reorganize themselves after every access operation using "splaying" (move-to-root via zick-zick or zick-zack rotations). Cost is amortized , but worst-case linear .
Treaps: Cartesian trees combining a Binary Search Tree (BST) for keys and a Max-Heap for priorities . If node contains :
- Left subtree:
- Right subtree:
- Both subtrees:
In a Randomized Treap, random priorities simulate uniform distribution, bounding expected height. Depth for a node is the expected sum of ancestor probabilities:
Module 2: Hashing
2.1 Hash Functions and Compression Maps
An occupancy factor denotes the ratio of stored keys to table size.
Common compression maps include:
- Division-Remainder:
- Multiply, Add, and Divide (MAD): Eliminates sequential patterns.
- Multiplicative Method: Utilizes an irrational number to divide intervals. The optimal constant is the Golden Ratio .
2.2 Collision Handling
Open Hashing (Closed Probing): Computes a probing sequence to resolve collisions:
- Linear Probing:
- Quadratic Probing:
- Double Hashing: Utilizes a secondary hash function:
Universal Hashing: Limits collision probability to . A standard universal set employs prime :
Module 3: Graph Algorithms and Flows
3.1 Transitive Closure & Traversal
- DFS & BFS: Vertex traversal mechanisms yielding lookup for adjacency. BFS resolves the shortest path in unweighted graphs.
- Floyd-Warshall: Derives the transitive closure considering paths through intermediate vertices . Operates in time.
3.2 Network Flows (Ford-Fulkerson)
Networks possess a source and sink . Flows must observe capacity limits ( ) and node conservation laws.
The Maximum Flow Minimum Cut Theorem declares that maximum flow equals the capacity of the minimum cut .
A Residual Network defines available capacity:
- Forward edge:
- Backward edge:
Using BFS to locate augmenting paths (Edmonds-Karp) binds runtime to:
Module 4: Community Analysis
4.1 Clustering and Density
Clustering Coefficient: Determines how tightly a node 's neighbors are connected.
(Where = existing connections between neighbors, and = degree)
4.2 Centrality Metrics
- Closeness Centrality: Reciprocal of average geodesic distance .
- Betweenness Centrality: Ratio of shortest paths passing through .
- Eigenvector Centrality: Proportional to the centrality of adjacent nodes.
Module 5: Monte Carlo Tree Search (MCTS)
MCTS guides decision processes in game trees (e.g., AlphaGo) through Selection, Expansion, Simulation, and Backpropagation.
Selection employs the Upper Confidence Bound applied to Trees (UCT) to balance exploitation and exploration:
Where is the total reward, is action visits, is parent visits, and is the exploration constant ( ).
Module 6: PRAM Algorithms
Parallel Prefix Summation: Aggregates array data iteratively over steps using parallel spawn instructions:
This mechanism allows rapid evaluation in shared-memory multiprocessor systems for array packing.