Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Similar documents
10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

14 Shortest Paths (November 8)

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

COMP108 Algorithmic Foundations

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

Paths, cycles and flows in graphs

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

CS 461, Lecture 17. Today s Outline. Example Run

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

CS 241 Analysis of Algorithms

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

Minimum Spanning Trees

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Garnir Polynomial and their Properties

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

Section 10.4 Connectivity (up to paths and isomorphism, not including)

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

Problem solving by search

QUESTIONS BEGIN HERE!

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

Numbering Boundary Nodes

Jonathan Turner Exam 2-10/28/03

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

Planar Upward Drawings

12. Traffic engineering

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Page 1. Question 19.1b Electric Charge II Question 19.2a Conductors I. ConcepTest Clicker Questions Chapter 19. Physics, 4 th Edition James S.

(a) v 1. v a. v i. v s. (b)

0.1. Exercise 1: the distances between four points in a graph

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

CS September 2018

Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

N=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f

The Cost Optimal Solution of the Multi-Constrained Multicast Routing Problem

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

CSI35 Chapter 11 Review

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

1 Introduction to Modulo 7 Arithmetic

TOPIC 5: INTEGRATION

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

Weighted Matching and Linear Programming

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Constructive Geometric Constraint Solving

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Scientific Programming. Graphs

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

Graph Search (6A) Young Won Lim 5/18/18

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

MULTIPLE-LEVEL LOGIC OPTIMIZATION II

Construction 11: Book I, Proposition 42

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

Weighted Graphs. Weighted graphs may be either directed or undirected.

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

Solutions to Homework 5

MCQ For Geometry. Similarity

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Section 3: Antiderivatives of Formulas

Lecture 20: Minimum Spanning Trees (CLRS 23)

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

Coalitional Manipulation for Schulze s Rule

Dominator Tree Certification and Independent Spanning Trees

O n t h e e x t e n s i o n o f a p a r t i a l m e t r i c t o a t r e e m e t r i c

CS 103 BFS Alorithm. Mark Redekopp

Binomials and Pascal s Triangle

1 Finite Automata and Regular Expressions

Polygons POLYGONS.

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

Last time: introduced our first computational model the DFA.

This chapter covers special properties of planar graphs.

WORKSHOP 6 BRIDGE TRUSS

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

Transcription:

Dt Strutur LECTURE Shortt pth lgorithm Proprti of hortt pth Bllmn-For lgorithm Dijktr lgorithm Chptr in th txtook (pp ). Wight grph -- rminr A wight grph i grph in whih g hv wight (ot) w(v i, v j ) >. A grph i wight grph in whih ll ot r. Two vrti with no g (pth) twn thm n thought of hving n g (pth) with wight. Th ot of pth i th um of th ot of it g: k w p w v i, v i i Exmpl: wight grph Two i proprti of hortt pth Tringl inqulity Lt G=(V,E) wight irt grph, w: E R wight funtion n V our vrtx. Thn, for ll g =(u,v) E: (,v) (,u) + w(u,v) Optiml utrutur of hortt pth Lt p = <v,.. v k > th hortt pth twn v n v k. Th u-pth twn v i n v j, whr i,j k, p ij = <v i,.. v j > i hortt pth. Ngtiv-wight g Shortt pth r wll-fin long thr r no ngtiv-wight yl. In uh yl, th longr th pth, th lowr th vlu th hortt pth h n infinit numr of g! - - Allow ngtiv-wight g, ut illow (or tt) ngtiv-wight yl! Shortt pth n yl Th hortt pth twn ny two vrti h no poitiv-wight yl. Th rprnttion for hortt pth twn vrtx n ll othr vrti i th m th on u in th unwigth BFS: rth-firt tr: G = (V,E ) uh tht V = {v V: [v] null} {} n E = {( [v],v), v V {}} W will prov tht rth-firt tr i hortt-pth tr for it root in whih vrti rhl from r in it n th uniqu impl pth from to v i hortt.

Exmpl: hortt-pth tr Exmpl: hortt-pth tr Etimt itn from our A for BFS on unwight grph, w kp ll whih i th urrnt t timt of th hortt itn twn n v. Initilly, it[] = n it[v] = for ll v, n [v] = null. At ll tim uring th lgorithm, it[v] (,v). At th n, it[v] = (,v) n ( [v],v) E Eg rlxtion Th pro of rlxing n g (u,v) onit of tting whthr it n improv th hortt pth from to v o fr y going through u. Rlx(u,v) if it[v] > it[u] + w(u,v) thn it[v] it[u] + w(u,v) [v] u Proprti of hortt pth n rlxtion Tringl inqulity = (u,v) E: (,v) (,u) + w(u,v) Uppr-ounry proprty v V: it[v] (,v) t ll tim, n it kp ring. No-pth proprty if thr i no pth from to v, thn it[v]= (,v) = Proprti of hortt pth n rlxtion Convrgn proprty if u v i hortt pth in G for om u n v, n it[u]= (,u) t ny tim prior to rlxing g (u,v), thn it[v]= (,v) t ll tim ftrwr. Pth-rlxtion proprty Lt p = <v,.. v k > th hortt pth twn v n v k. Whn th g r rlx in th orr (v, v ), (v, v ), (v k-, v k ), thn it[v k ]= (,v k ). Pror u-grph proprty on it[v]= (,v) v V, th pror ugrph i hortt-pth tr root t.

Two hortt-pth lgorithm. Bllmnn-For lgorithm. Dijktr lgorithm Gnrliztion of BFS Bllmn-For lgorithm: ovrviw Allow ngtiv wight. If thr i ngtiv yl, rturn ngtiv yl xit. Th i: Thr i hortt pth from to ny othr vrtx tht o not ontin non-ngtiv yl (n limint to prou hortr pth). Th mximl numr of g in uh pth with no yl i V, u it n hv t mot V no on th pth if thr i no yl. it i nough to hk pth of up to V g. Bllmn-For lgorithm Bllmn - For( G, ) Initiliz( G, ) for i to V for h g u, v E o if it[v] it[u] w u, v it[ v ] it[ u] w( u, v ) [ v ] u for h g u, v E if it v u w u, v rturn " ngtiv yl" Exmpl: Bllmn-For lgorithm () - - - Eg orr (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) Exmpl: Bllmn-For lgorithm () Exmpl: Bllmn-For lgorithm () Eg Eg orr orr - (,) - (,) (,) (,) - (,) - (,) - (,) (,) (,) - (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) (,)

Exmpl: Bllmn-For lgorithm () - - - Eg orr (,) (,) (,) (,) (,) (,) (,) (,) (,) (,) Exmpl: Bllmn-For lgorithm () Eg orr - (,) (,) - (,) (,) - (,) (,) (,) (,) (,) - (,) Bllmn-For lgorithm: proprti Th firt p ovr th g only nighor of r fft (-g pth). All hortt pth with on g r foun. Th on p hortt pth with g r foun. Aftr V - p, ll poil pth r hk. Clim: w n to upt ny vrtx in th lt p if n only if thr i ngtiv yl rhl from in G. Bllmn For lgorithm: proof () On irtion w lry know: if w n to upt n g in th lt itrtion thn thr i ngtiv yl, u w prov for tht if thr r no ngtiv yl, n th hortt pth r wll fin, w fin thm in th V itrtion. W lim tht if thr i ngtiv yl, w will iovr prolm in th lt itrtion. Bu, uppo thr i ngtiv yl v,... vk, vk v But th lgorithm o not fin ny prolm in th lt itrtion, whih mn tht for ll g, w hv tht it [v] it[u] w( u, v) for ll g in th yl. Bllmn For lgorithm: proof () Proof y ontrition: for ll g in th yl it[v] it[v] w v, v it[v ] it[v ] w v, v... it[vk ] it[vk- ] w vk, vk k k k it[ vi ] it[ vi] w( vi, vi ) i i i Aftr umming up ovr ll g in th yl, w iovr tht th trm on th lft i qul to th firt trm on th right (jut iffrnt orr of ummtion). W n utrt thm, n w gt tht th yl i tully poitiv, whih i ontrition. Bllmn-For lgorithm: omplxity Viit V vrti O( V ) Prform vrtx rlxtion on ll g O( E ) Ovrll, O( V. E ) tim n O( V + E ) p.

Bllmn-For on DAG Exmpl: Bllmn-For on DAG () For Dirt Ayli Grph (DAG), O( V + E ) rlxtion r uffiint whn th vrti r viit in topologilly ort orr: DAG-Shortt-Pth(G). Topologilly ort th vrti in G. Initiliz G (it[v] n (v)) with our.. for h vrtx u in topologilly ort orr o. for h vrtx v inint to u o. Rlx(u,v) - Vrti ort from lft to right - Exmpl: Bllmn-For on DAG () Exmpl: Bllmn-For on DAG () - - - - Exmpl: Bllmn-For on DAG () Exmpl: Bllmn-For on DAG () - - - -

Exmpl: Bllmn-For on DAG () Exmpl: Bllmn-For on DAG () - - - - Bllmn-For on DAG: orrtn Pth-rlxtion proprty Lt p = <v,.. v k > th hortt pth twn v n v k. Whn th g r rlx in th orr (v, v ), (v, v ), (v k-, v k ), thn it[v k ]= (,v k ). In DAG, w hv th orrt orring! Thrfor, th omplxity i O( V + E ). Dijktr lgorithm: ovrviw I: Do th m BFS for unwight grph, with two iffrn: u th ot th itn funtion u minimum priority quu int of impl quu. Th BFS lgorithm BFS(G, ) ll[] urrnt; it[] = ; [] = null for ll vrti u in V {} o ll[u] not_viit; it[u] = ; [u] = null EnQuu(Q,) whil Q i not mpty o u DQuu(Q) for h v tht i nighor of u o if ll[v] = not_viit thn ll[v] urrnt it[v] it[u] + ; [v] u EnQuu(Q,v) ll[u] viit Exmpl: BFS lgorithm

Exmpl: Dijktr lgorithm Dijktr lgorithm Dijktr(G, ) ll[] urrnt; it[] = ; [u] = null for ll vrti u in V {} o ll[u] not_viit; it[u] = ; [u] = null Q whil Q i not mpty o u Extrt-Min(Q) for h v tht i nighor of u o if ll[v] = not_viit thn ll[v] urrnt if [v] > [u] + w(u,v) thn [v] [u] + w(u,v); [v] = u Inrt-Quu(Q,v) Dt Strutur, ll[u] Spring L. = Jokowiz viit Exmpl: Dijktr lgorithm () Exmpl: Dijktr lgorithm () Exmpl: Dijktr lgorithm () Exmpl: Dijktr lgorithm ()

Exmpl: Dijktr lgorithm () Exmpl: Dijktr lgorithm () Dijktr lgorithm: orrtn () Thorm: Upon trmintion of th Dijktr lgorithm, for h it[v] = (,v) for h vrtx v V, Dfinition: pth from to v i i to pil pth if it i th hortt pth from to v in whih ll vrti (xpt my for v) r ini S. Lmm: At th n of h itrtion of th whil loop, th following two proprti hol:. For h w S, it[w] i th lngth of th hortt pth from to w whih ty ini S.. For h w V S, it(w) i th lngth of th hortt pil pth from to w. Dijktr lgorithm: orrtn () Proof: y inution on th iz of S. For S =, it i lrly tru: it[v] = xpt for th nighor of, whih ontin th lngth of th hortt pil pth. Inution tp: uppo tht in th lt itrtion no v w to S. By th inution umption, it[v] i th lngth of th hortt pil pth to v. It i lo th lngth of th gnrl hortt pth to v, in if thr i hortr pth to v ping through no of S, n x i th firt no of S in tht pth, thn x woul hv n lt n not v. So th firt proprty till hol. Th Dt Strutur, thorm Spring L. Jokowiz follow whn S = V. Dijktr lgorithm: orrtn () Proprty : Lt x S. Conir th hortt nw pil pth to w If it on t inlu v, it[x] i th lngth of tht pth y th inution umption from th lt itrtion in it[x] i not hng in th finl itrtion. If it o inlu v, thn v n ithr no in th mil or th lt no for x. Not tht v nnot no in th mil in thn th pth woul p from to v to y in S, ut y proprty, th hortt pth to y woul hv n ini S v n not inlu. If v i th lt no for x on th pth, thn it[x] ontin th itn of tht pth, y th utitution it[x] = it[v] + w(v,x) in th lgorithm. Dijktr lgorithm: omplxity Th lgorithm prform V Extrt-Min oprtion n E Inrt-Quu oprtion. Whn th priority quu i implmnt hp, inrt tk O(lg V ) n Extrt-Min tk O(lg( V ). Th totl tim i O( V lg V ) + O( E lg V ) = O( E lg V ) Whn E = O( V ), thi i not optiml. In thi, thr r mny mor inrt thn xtrt oprtion. Solution: Implmnt th priority quu n rry! Inrt will tk O() n Extrt-Min O( V ) O( V ) + O( E ) = O( V ) whih i ttr thn th hp long E i O( V /lg ( V )).

Applition: iffrn ontrint Givn ytm of m iffrn ontrint ovr n vril, fin olution if on xit. x i x j k for i, j n n k m Contrint grph G: h vril x i i vrtx, h ontrint x i x j k i irt g from x i to x j with wight k. Whn G o not hv ngtiv yl, th minimum pth itn of th vrti r th olution to th ytm of ontrint iffrn. Exmpl: iffrn ontrint () x x x x - x x x x x x x x - x x - x x - Solution: x = (-,-,,-,-) x - x - - x x - x Exmpl: iffrn ontrint Solution: x = (-,-,,-,-) x - - - - - x x x x - - - Why o thi work? Thorm: Lt Ax t of m iffrn ontrint ovr n vril, n G=(V,E) it orrponing ontrint grph. If G h no ngtiv wight yl, thn x = ( (v,v ), (v,v ),, (v,v n )) i fil olution for th ytm. If G h ngtiv yl, thn thr i no fil olution. Proof outlin: For ll g (v i,v j ) in E: (v,v j ) (v,v i ) + w(v i,v j ) (v,v j ) (v,v i ) w(v i,v j ) x j x j w(v i,v j ) Summry Solving th hortt-pth prolm on wight grph i prform y rlxtion, on th pth tringl inqulity: for ll g =(u,v) E: (,v) (,u) + w(u,v) Two lgorithm for olving th prolm: Bllmn For: for h vrtx, rlxtion on ll g. Tk O( E. V ) tim. Work on grph with nonngtiv yl. Dijktr: BFS-lik, tk O( E lg V ) tim.