{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS Notes 16 - o Run Time O(n e • Step 0 O(n e • Step 1...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern