Test 2 Review
for CMPS 2200, Fall 2012
Relevant Material:
- All material from 10/3/12 until 10/30/12 (inclusive).
- This includes material covered in the lectures, and homeworks 5 - 7.
- The covered chapters in the book are 3.1,2,3 (not 3.4), 4, 5.1. Note that on some of the topics we covered additional details in the lectures (e.g., topological sort, amortized analysis).
- 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 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 variants of
graph representations(lists or matrix) are used.
- 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)
- Modify Dijkstra's/Bellman-Ford's algorithm for special cases of graphs to improve runtime or space.
- Minimum Spanning Tree(MST)
- Prim
- Runtime: Θ(|V|).TEXTRACT-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.
- Heaps
- Min-heap property, heap definition
- Using array implementation, findMin takes O(1) time, and extractMin and decreaseKey take O(log n) time
- Heapsort: Repeatedly extract min in min-heap (or extract max in max-heap); O(log n) time
- Amortized Analysis & Union-Find:
- Aggregate analysis, accounting method
- Dynamic tables, binary counter
- Union-Find:
- Union-find data structure definition (operations)
- Union-find: List implementation, tree implemention
- Union by weight/rank, path compression