Final Review
[Roughly 40-50% from new material, 60-50% from other (materials covered in
midterm 1 and 2 )]
- Review for Test 1
- Review for Test 2
- New Material:
- Graphs
- Representation of Graphs:
- Adjacency Matrix
- Adjacency Lists
- Graph Algorithms
- Graph Traversal: Assignment of timestamp
depends on order of vertices in adjacency lists or matrix, for example:
if vertices are alphabetically ordered then if a has b,c and d in its
list then b will be visited/discovered first from a, not c or d (this
concept also applies for adjacency matrix).
- Breadth First Search:
- Runtime: O(|V|+|E|) [if adjacency lists are given]
- If the graph is given in an adjacency matrix, the time complexity of
BFS_iter(G) will change. Why?
- Depth First Search:
- Runtime: O(|V|+|E|) [if adjacency lists are given]
- DFS edge classification
- Directed Acyclic
Gragh(DAG) and Topological Sort
- If the graph is given in an adjacency matrix, the time complexity of
DFS_rec(G) will change. Why?
- Minimum Spanning Tree(MST)
- Prim
- Runtime: Θ(|V|).T
EXTRACT-MIN + Θ(|E|).TDECREASE-KEY
- Runtimes using different variants of graph
representations and priority queue(linked list,
min-heap or array)
- Kruskal
- Runtime: O(|E|log|E|) which comes from sorting all
the edges.
- Shortest Path Algorithms
- Single Source Shortest Paths
- Dijkstra: It works only for
non-negative edge weights.
- Runtime: Θ(|V|).T
EXTRACT-MIN + Θ(|E|).TDECREASE-KEY
- Runtimes using different variants of graph
representations and priority queue(linked list,
min-heap or array)
- Bellman-Ford: It works for any edge
weights and can detect negative weight cycle.
- Runtime: O(|V||E|)
- For a DAG, run Topological Sort and then one round of Bellman-Ford. runtime O(|V|+|E|)
- All Pairs Shortest Paths
- Floyd-Warshall:
- Runtime: O(|V|^3) [when adjacency matrix is
given]
- Dijkstra: Run single source
Dijkstra once for each vertex as source.
- Bellman-Ford: Run single source Bellman-Ford
once for each vertex as source.
- P and NP
- Definition of P, NP, NP-hard, NP-Complete
- Reductions, NP-complete problems (SAT, Clique, TSP, HC, Vertex Cover, Independent Set)