DOC PREVIEW
MIT 6 006 - Lecture 14- Shortest Paths I

This preview shows page 1-2-3-26-27-28 out of 28 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 28 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.006Introduction to AlgorithmsLecture 14: Shortest Paths IProf. Erik DemaineToday• Shortest paths• Negative‐weight cycles• Triangle inequality• Relaxation algorithm• Optimal substructureShortest PathsShortest PathsHow Long Is Your Path?• Directed graph • Edge‐weight function • Path   • Weight of , denoted , is     v1v2v3v4v54−2 −51Example:My Path Is Shorter Than Yours• A shortest path from to is a path of minimum possible weight from to • The shortest‐path weight from to is the weight of any such shortest path:BADCExample:14372BADC14372 , 6You Can’t Get There From HereYou Can’t Get There From Here• If there is no path from to , then neither is there a shortest path from to • Define in this caseBACExample:14237DThe More I Walk,The Less It Takes• A shortest path from to might not exist, even though there is a path from to • Negative‐weight cycle   hasBACExample:123−7DThe More I Walk,The Less It Takes• Define if there’s a path from to that visits a negative‐weight cycle •BACExample:123−7Dst25−2310Single‐Source Shortest Paths• Problem: Given a directed graph with edge‐weight function , and a source vertex , compute for all BACExample:1237Dst25−231001−2840Shortest‐Path Tree• Ideally also compute a shortest‐path treecontaining a shortest path from source to every (assuming shortest paths exist)– Represent by storing parent for each BACExample:1237Dst25−231001−2840Shortest‐Path Trees• Ideally also compute the union of one shortest path from source to every , which forms the shortest‐path treebicycle travel inSan Francisco areabicycle travel inSeattle areaBrandon Martin‐Anderson& Nino Walkerhttp://graphserver.sourceforge.net/gallery.htmlSingle‐Source Shortest ‐Path Algorithms• Relaxation algorithm (TODAY)– Framework for most shortest‐path algorithms– Not necessarily efficient• Bellman‐Ford algorithm (LECTURE 15)– Deals with negative weights– Slow but polynomial• Dijkstra’s algorithm (LECTURE 16)– Fast (nearly linear time)– Requires nonnegative weightsBrute‐Force Algorithm• Number of paths can be infinite:return encountered with smallest BAC123−7Dst25−2310Brute‐Force Algorithm• Number of paths can be exponential:## assume no negative‐weight cyclesreturn encountered with smallest svnv1v2…= tpaths from to ; vertices and edgesRelaxation• In general, refers to letting a solution (temporarily) violate a constraint, and trying to fix these violationsMagic Geekhttp://www.youtube.com/ watch?v=Y12daEZTUYoTriangle Inequality• Theorem: For all , we have• Proof: Shortest path from to is at most any particular path, e.g., the blue chain. uxvRelaxation Approach• Maintain distance estimatefor each • Goal: for all • Invariant:• Initialization:• Repeatedly improve estimates toward goal, by aiming to achieve triangle inequalityin :Edge Relaxation• Consider an edge • [triangle ineq.][candidate path]uvs:Relaxation Algorithmfor in :while some edge has :pick such an edge relax :if :uvsRelaxation Algorithmwith Shortest‐Path Treefor in :while some edge has :pick such an edge relax :if :uvsRelaxing Is Safe• Lemma: The relaxation algorithm maintains the invariant that for all .• Proof: By induction on the number of steps.– Consider relax– By induction, – By triangle inequality,– So setting is “safe” uvsInfinite Relaxation• If a negative‐weight cycle is reachable from , then relaxation can never terminateBAC123−7Dst25−23100∞∞∞∞∞Long Relaxationv1v2v3v4v5v7v688844422211…0 ∞∞∞∞∞∞Long Relaxation• Analysis:– relax – relax – recurse on   – relax – recurse on   v1v2v3v4v5v7v688844422211…0 ∞∞∞∞∞∞/Are You SureThis Is a Good Idea?• Bellman‐Ford algorithm: (LECTURE 15)– Relax all of the edges– Repeat times– Polynomial time!• Dijkstra’s algorithm: (LECTURE 16)– Relax edges in a growing ball around – Nearly linear time!– (but doesn’t work with negative edge weights)Optimal Substructure• Lemma: A subpath of a shortest path is a shortest path (between its endpoints).• Proof: By contradiction.– If there were a shorter path from to ,then we could shortcut the path from to , contradicting that we had a shortest path.


View Full Document

MIT 6 006 - Lecture 14- Shortest Paths I

Documents in this Course
Quiz 1

Quiz 1

7 pages

Quiz 2

Quiz 2

12 pages

Quiz 2

Quiz 2

9 pages

Quiz 1

Quiz 1

10 pages

Quiz 2

Quiz 2

11 pages

Quiz 1

Quiz 1

12 pages

Graphs

Graphs

27 pages

Load more
Download Lecture 14- Shortest Paths I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 14- Shortest Paths I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 14- Shortest Paths I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?