CMPSC 130A Algorithms and Data Structures
Algorithm analysis and graph algorithms including shortest path, 2-SAT, and minimum spanning tree.
CMPSC 130A
- Graph Traversal.
- Depth-First Search (DFS)
- Breadth-First Search (BFS)
- Topological Sort.
- Connected Components.
- Connected Components (CCs)
- Strongly Connected Components (SCCs)
- 2-SAT.
- Shortest Path.
- Unweighted Graphs: BFS
- Dijkstra's Algorithm
- Bellman-Ford Algorithm
- Minimum Spanning Tree.
- Prim's Algorithm (like Dijkstra's)
- Kruskal's Algorithm (uses Union-Find)
- Cut Property (statement and proof)
- Union-Find.
- Hash Tables.
- Chain Hashing (best of 2)
- Bloom Filter
- Cuckoo Hashing
- Perfect Hashing
- Balanced Binary Search Trees.
- Binary Search Tree (BST)
- AVL Tree
Algorithm Analysis with Big-O
Common complexities: , , , , , , .
- Big-O: if such that . ( upper bound)
- Big-Omega: if such that . ( lower bound)
- Big-Theta: if such that . ( tight bound)
Master Theorem
For where :
- If for some , then .
- If for some , then .
- If for some and for some and sufficiently large , then .
Patterns
:
Markov Chains
states, transition stochastic matrix where is the probability of transitioning from state to state .
The sum of each row in is 1.
Let (vector) be the state distribution at time . Then .
As , approaches a matrix with identical rows, and converges to a stationary (limiting) distribution such that . .
means is a left eigenvector of with eigenvalue 1. Since is stochastic, 1 is the largest eigenvalue.
Ergodic Markov Chains
If such that all entries of are positive, then the Markov chain is ergodic. In the graph, for every pair of states , there is a path from to of length .
Theorem: For a finite ergodic Markov chain, there exists a unique stationary distribution with all positive entries.
A graph is ergodic iff it is irreducible and aperiodic.
- Irreducible (strongly connected): for every pair of states , there is a path from to .
- Aperiodic (non-bipartite): the gcd of the lengths of all cycles in the graph is 1.
If is symmetric (), then the stationary distribution is uniform: for all . If , then is the stationary distribution (detailed balance condition). is reversible with respect to .
PageRank (Google's Algorithm)
Method to measure the importance of web pages using a Markov chain model of web surfing.
is a directed graph where vertices are web pages and edges are hyperlinks.
Ideas:
- number of citations -- in-degree.
- every page has 1 citation to give, then each linked from gets citation from .
- recursive definition: important pages are linked by other important pages.
Lazy random surfer model: with probability follow a link, with probability jump to a random page. This is ergodic because .
where is the all-ones matrix and is the sparse matrix defined above.