Final Review
[Roughly 40% from new material, 60% from other ( materials covered in
midterm 1 and 2 )]
- Review for midterm 1:
html,
pdf,
- Review for midterm 2
- New Material:
- Graphs
- Representation of Graphs:
- Adjacency Matrix
- Adjacency Lists
- Sample Questions
- Come up with an algorithm to convert given adjacency
lists to matrix or vice versa.
- 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 adjacency matrix is given 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 adjacency matrix is given complexity of
DFS_rec(G) will change. Why?
- Sample Questions:
- For a given graph give discover/finish time using
DFS
- For a given graph give visit time using BFS
- Runtimes of BFS and DFS when different varients of
graph representations(lists or matrix) are used.
- 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.
- Sample Questions:
- For a given graph run Prim's algorithm and show all
different steps(vertex weights, priority queue,
predecessor array)
- For a given graph run Kruskal's algorithm and show
the subsets of different steps.
- 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|)
- Sample Questions:
- For a given graph run Dijkstra's/Bellman-Ford algorithm and
show all different steps(vertex weights, priority
queue, predecessor array)
- 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.
- Sample Questions
- Analyze the runtime of Floyd-Warshall if
adjacency lists are given instead of adjacency
matrix.