CS Notes 16

CS Notes 16 - o Run Time: O(n+e) Step 0: O(n+e) Step 1:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Connectedness for directed graphs Weakly connected o Connected, ignoring edge directions Strongly connected o Every vertex is reachable from every vertex Applications 1. Topological sorting o e.g. course pre-req graph o Sequence all tasks such that all precedence constraints are met o Graph must be directed and acyclic o If x-> y is an edge then x must appear before y (not necessarily immediately before) o Top sort Using DFS Start anywhere, go as far as you can go Number a vertex when you back up from it Return an array of the vertex numbers 1. BFS based topSort o Step 0: (Preprocessing): Count # of incoming edges to each vertex (predecessor/precedence count); o Step 1: Give topological numbers 0. .k to the vertices with 0 predecessor count, enqueue item o Step 2: while queue is not empty do v<- dequeue() For each neighbor w of v do Pred[w]--; If pred[w]==0, give w the next top num, enqueue
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: o Run Time: O(n+e) Step 0: O(n+e) Step 1: O(n) Step 2: O(e) Overall: O(n+e) Dijkstra's Shortest Path Algorithm Weighted graphs (Positive) Used for finding the shortest distance between point a to point b "Greedy" algorithms o Go for the best current solution, then correct later if a better solution is found o Trial and error Similar to BFS Need an array that contains the best path from the sources to that vertex Array D stores current best distance from source to each vertex Array Previous keeps for each vertex, the previous vertex n current shortest path from source to it Fringe: set of all vertices that are not done & have non Step Done D[B] D[C] D[D] D[E] D[F] D[G] A 5 10 1 B-10 11 8 2 E-10 10 10 A 0 C 2 B 1 D 3 E 4...
View Full Document

This note was uploaded on 02/29/2012 for the course 198 112 taught by Professor Venugopal during the Spring '09 term at Rutgers.

Page1 / 2

CS Notes 16 - o Run Time: O(n+e) Step 0: O(n+e) Step 1:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online