Algorithms and Data Structures

Size: px
Start display at page:

Download "Algorithms and Data Structures"

Transcription

1 Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 08

2 Part : Graphs The four colour problem dating back to 8 source: wikipedia.org source: math.gatech.edu PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

3 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

4 Fundamentals definitions relation U V fundamental formalism in order to express relations between entities of basic sets U and V example U : set of airlines LH, LX, OS, BA, EN, AF, IB,... V : set of airports MUC, HAM, LHR, ZRH, DUB, DBX, EWR,... : relation airline u flies to v with u U, v V Cartesian product U V set of all ordered pairs (u, v) with u U, v V LH BA LX EN U U V V SEA ZRH BHX MUC FLR LH BA LX EN U U V V SEA ZRH BHX MUC FLR PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

5 Fundamentals definitions (cont d) usual case: homogeneous relation V V with (finite) basic set V set of persons V with relation person x knows person y with x, y V given: basic set V v i of elements v i that are numbered with i 0,..., n and which is called set of vertices hence, a directed graph G (V, E) is given by the set of vertices V and some relation E V V elements (v, v ) E are called edges and E as the set of edges; instead of (v, v ) more often edges are written as v v example a b a b a b c d c d c d different representations of the same directed graph PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

6 Fundamentals definitions (cont d) if relation is symmetric, then with v v also v vbelongs to E the relation between vertices v, v is said to be mutual graphs with these properties are called general or undirected graphically, edges are not drawn as arrows but as simple lines a b c d source: mvg.de network: undirected graph with V as set of stations and E as connexion between always two stations of commuter trains PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 6

7 Fundamentals definitions (cont d) the inverse relation conforms to the dual graph G T (V, E T ) with (v, v ) E T if and only if (v, v) E hence, in G T all edges are reversed, i.e. from v v follows v v obviously, if holds the graph is undirected the output set v of some vertex v is defined as set of edges starting in v correspondingly, the input set v is defined as set of edges ending up in v v and v are called in degree or out degree, resp., of some vertex v summing up over all vertices of a directed graph the following holds in undirected graphs, every edge starting in some vertex v also ends up in the same vertex v, hence v v for all v V more general, one speaks of the degree deg(v) of some vertex v PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 7

8 Fundamentals something more about graphs a sequence (v 0, v,..., v n ) of edges (v i, v i ) E with i 0,..., n is called path of length n from vertex v 0 to vertex v n v n is reachable from v 0 a path of length n is called cycle if v 0 v n a directed graph (DG) that contains no directed cycles (i.e. with all edges being oriented in the same direction) is called acyclic v 0 v v 0 v 3 path of length n cycle of length n 3 a cycle is called simple if all vertices v i with i n are different it is called Euler cycle if each edge of the DG is visited exactly once it is called Hamiltonian cycle if each vertex of the DG is visited exactly once PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 8

9 Technische Universität München Fundamentals something more about graphs (cont d) example: Seven Bridges of Königsberg Königsberg set on both sides of Pregel River with islands A (dome), B and mainland portions C, D all connected by seven bridges find (closed) walk through city crossing each bridge only once C deg(c) 3 C deg(b) 3 deg(a) A source: landkartenarchiv.de A B B deg(d) 3 D D solution given by L. EULER (763): closed walk if and only if each vertex has an even degree until 9 capital of East Prussia and residence of Kant, Kollwitz, E.T.A. Hoffmann, Hilbert,...; since 96 Kaliningrad (today Russia) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 9

10 Fundamentals something more about graphs (cont d) path (v, v) of length n is called loop, i.e. connecting a vertex to itself any relation is called reflexive iff for each vertex exists one loop is called irreflexive if no cycle of length n exists ( simple graph) an undirected graph is called complete if every pair of distinct vertices is connected by a unique edge also referred to as graph E n with n V denoting the number of vertices complete graphs E 3, E, E, and E 6 question: how to store graphs efficiently...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 0

11 Fundamentals storage: adjacency matrix let G (V, E) be a directed graph with vertices v i numbered from,..., n storage of G as adjacency matrix, i.e. as n n matrix A (a ij ) with a ij, if (v i, v j ) K 0, otherwise for set E V V example v v v 3 v v v v 0 A v v 3 v 3 v 0 0 v for undirected graphs follows with a ij also a ji, hence A A T, i.e. A is symmetric PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

12 Fundamentals storage: adjacency list let G (V, E) be a directed graph with vertices v i numbered from,..., n if G is not dense, storage as adjacency list is advantageous idea: for each vertex all adjacent vertices are stored within a linked list example v v v v v 3 v v v 3 v 3 v 3 v v v v 3 for undirected graphs follows with (v i, v j ) E that list v i has to store element [v j ] and list v j has to store element [v i ] redundancy simple operations such as deletion of a vertex are not properly supported by this representation list of adjacent vertex has to be modified, too PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

13 Fundamentals storage: incidence matrix let G (V, E) be an irreflexive graph with vertices v i numbered from,..., n and edges e j numbered from,..., m storage of G as incidence matrix, i.e. as n m matrix B (b ij ) with, if e j (v i, ) b ij 0, if v i e j, if e j (, v i ) or b ij, if v i e j 0, otherwise for directed graphs for undirected graphs for set E V V in case of directed graphs, each column of B contains exactly one (start vertex) and one (end vertex); in case of undirected graphs, each column of B has two entries different from 0 PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

14 Fundamentals storage: incidence matrix (cont d) example e e e 3 e e e 6 e v v v e e B v v 3 e 3 e v 3 v e v observation: each column of B sums up to zero résumé as always, representation is problem dependent typically, graphs are stored as adjacency matrix caution when storing huge graphs ( memory footprint (!)) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

15 Fundamentals edge weighted graphs let G (V, E) be a directed or undirected graph each edge e has one additional attribute w(e), called weight instead of (i.e. e : v i v j E) the adjacency matrix A (a ij ) stores the corresponding weight w(e); possible meanings length in [m] cost in [ ] flow in [l s] example v v v 3 v v 3 v v 0 3 A v v 3 v 3 v 0 0 v PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

16 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 6

17 Minimum Spanning Tree knocking on wood... let G (V, E) be an acyclic undirected graph with edge weights w(e) G is called tree if each two vertices are connected via one path only for trees V E holds as for one edge less the graph would not be connected for one edge more the graph would contain at least one cycle definition: spanning tree A set of edges T E is called spanning tree of G, if and only if (V, T) is a tree. graph G possible spanning trees of G PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 7

18 Minimum Spanning Tree knocking on wood... (cont d) weight of subset E Edefined as definition: minimal spanning tree A spanning tree T E is called minimal spanning tree of G, if there exists no spanning tree of G with smaller weight than w(t). for instance, spanning trees are an important topic within planning of communication networks or electric power grids reachability of all vertices (e.g. cities) with minimal cost (e.g. cables, excavations,...) computation of minimal spanning tree via algorithm from KRUSKAL (96) or PRIM (97) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 8

19 Minimum Spanning Tree PRIM algorithm let T be the set of edges selected so far forming a minimum spanning tree then further edges are chosen thus w(t) is increased by a minimum only hence, the next edge (v, v ) to be included in T ) has to be a minimum cost edge not in T ) with the property that T (v, v ) is also a tree T possible next edges edge violates rule ) the idea for this algorithm is referred to the American computer scientist R.C. PRIM, nevertheless it was originally discovered in 930 by the Czech mathematician V. JARNÍK and, thus, is also called PRIM JARNÍK algorithm PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 9

20 Minimum Spanning Tree PRIM algorithm (cont d) preliminary: set of edges T is empty and cost C(T) 0. find edge e : (v i, v j ) with minimal weight w(e). tag vertices v i, v j, store e in T, and update C(T) C(T) w(e) initialisation (V ) 3. find next edge e : (v, v ) such that loop over all vertices i. vertex v is tagged ii. vertex v is untagged iii. edge e has minimal weight w(e ) depends on the implementation. tag vertex v, store e in T, and update C(T) C(T) w(e ). repeat steps 3. and. until all vertices are tagged for simplicity, V (instead of V ) denotes the number or vertices and E (instead of E ) the number of edges PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 0

21 PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 Technische Universität München 6 7 E D E C D E 6 7 Minimum Spanning Tree PRIM algorithm (cont d) example C 3 6 B D E 7 7 D B E 6 7 E D C C(T) C(T) 3 C(T) E D C(T) E C(T) E B C D F A A F C(T) 0 F A A B F 3 A B C D E F A B C D F A B C F

22 Minimum Spanning Tree implementation and complexity how to find the next edge efficiently...? idea: associate with each vertex v a value NEAR(v) thus NEAR(v) 0 in case vertex v is already flagged (and included in T) NEAR(v) 0 and A(v, NEAR(v)) is minimum otherwise hence, next edge is defined by NEAR(v) 0 and A(v, NEAR(v)) is minimum note: in case (v, v ) E the regarding coefficient must be set to a ij initialisation of NEAR( ), assuming v, v are the first two vertices being flagged and, thus, e : (v, v ) being the edge with minimal weight w(e) of G for i 0 to V do if A(i, v) A(i, v ) then NEAR(i) v else NEAR(i) v fi od NEAR(v) 0; NEAR(v ) 0 (V) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

23 Minimum Spanning Tree implementation and complexity (cont d) algorithm fragment conforms to E V times for i to V do find next edge with NEAR(v) 0 and A(v, NEAR(v)) minimum update... for k 0 to V do if NEAR(k) 0 and A(k, v) A(k, NEAR(k)) then NEAR(k) v fi od od (V) complexity start: finding minimal edge and initialisation of NEAR( ) (V ) algorithm: V times update of NEAR( ) (V ) hence, PRIM belongs to class (V ) with quadratic runtime complexity optimised versions for sparse graphs with ((E V) log (V)) steps PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

24 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

25 Single Source Shortest Path routing problem: what is the shortest path from x to y... turn left in 0 metres take first exit left drive 900 metres and arrive at destination source: maps.google.de 7 A E F 3 B D 6 C let G (V, E) be a simple graph with positive edge weights w(e) G stored as adjacency matrix with a ij in case (v i, v j ) E PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

26 Single Source Shortest Path routing (cont d) let v 0 and v k be two arbitrary vertices of graph G i. is there a path from v 0 to v k...? ii. if there is more than one path, which is the shortest...? both i. and ii. are special cases of the general path problem single source shortest path (SSSP): starting from one dedicated vertex s, find all shortest paths to all other vertices v V SSSP was studied by E.W. DIJKSTRA and the regarding algorithm is referred to as DIJKSTRA algorithm (99) GO TO considered harmful. (960) source: thocp.net PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 6

27 Single Source Shortest Path something about complexity... combinatorial explosion (brute force search) s e... e layer layer 0 number of vertices V #layers V 0 number of paths P #layers P 0,,899,906,8,6 assumption: computer is able to test,000,000 path every second runtime for above problem: 36 years (!) with 60 layers 37,000 years; with 70 layers 37,000,000 years PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 7

28 Single Source Shortest Path something about complexity... (cont d) idea: do not test all paths, only investigate further in those which have been found shortest so far w(e) denotes the length of edge e : v v, also written as w(v, v ) length of path p (v 0, v,..., v k ) from v 0 ( s) to v k ( t) is defined as definition: shortest path p is called shortest path from s to t if there is no path p from s to t with w(p ) w(p). The length of path from s to t is called distance and denoted with (s, t). In case there exists no path from s to t then (s, t). solution to above problem DIJKSTRA algorithm PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 8

29 Single Source Shortest Path DIJKSTRA algorithm compute spanning tree which starting in some vertex s V successively finds all shortest paths to all other vertices thus, shortest paths (SP) are computed in nondecreasing order, i.e. find path to nearest vertex first, then to second nearest, then to third,... Let p (v 0, v,..., v k ) be the shortest path from v 0 to v k. For each pair i, j with 0 i j k path p ij (v i, v i,..., v j ) is then a shortest path from v i to v j. assume, path from v 0 to v k contains vertex u to which no SP was found yet then path looks like (v 0,..., u,..., v k ) with w(v 0, u) w(v 0, v k ) this violates our assumption paths are generated in nondecreasing order, hence a shortest path to u must already have been found furthermore: for shortest path p (v 0, v,..., v k ) from v 0 to v k holds (v 0, v k ) (v 0, v k ) w(v k, v k ) important for finding next edge to be included in T PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 9

30 Single Source Shortest Path DIJKSTRA algorithm (cont d) preliminary: set of edges T is empty and start vertex s has been chosen. initialise distance to each vertex v V with (s, v). tag vertex s, set (s, s) 0, and continue with step. (where v s) initialisation 3. find next vertex v loop over all vertices i. that is not tagged ii. whose distance (s, v ) is minimal. tag vertex v and store edge e : (v p, v ) from predecessor v p to v in T. test for all untagged vertices v if a shorter path via v exists, thus that (s, v ) w(v, v ) (s, v ) and if so update (s, v ) and store v as predecessor of v 6. repeat steps 3. to. until all vertices are tagged PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 30

31 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E A 7 E F B 6 D C A B C D E F v p v p v p v p v p 0 B B 6 B B v p PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

32 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E A B C D E F v p v p v p v p v p v p A B 0 B B 6 B B F C B 6 B 9 A 3 A 7 E 6 D PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

33 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E 7 A E F B 6 D C A v p B B v p 0 C v p D v p E v p F v p B 6 B B B 6 B 9 A 3 A B 6 B 8 F PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 33

34 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E 7 A E F B 6 D C A v p B B v p 0 C v p D v p E v p F v p B 6 B B B 6 B 9 A 3 A B 6 B 8 F C 8 F PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

35 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E 7 A E F B 6 D C A v p B B v p 0 C v p D v p E v p F v p B 6 B B B 6 B 9 A 3 A B 6 B 8 F C 8 F 7 D PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

36 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E 7 A E F B D 6 C A v p B B v p 0 C v p D v p E v p F v p B 6 B B B 6 B 9 A 3 A B 6 B 8 F C 8 F 7 D PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 36

37 Single Source Shortest Path DIJKSTRA algorithm (cont d) example: starting point is vertex B with destination E A E F B D C A B C D E F v p v p v p v p v p v p 0 B B 6 B B B 6 B 9 A 3 A B 6 B 8 F C 8 F 7 D B 0 B C 7 D 3 A path: B C D E with (B, E) 7 algorithm finds all shortest paths from vertex B to all other vertices for different starting points typically different spanning trees are computed PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 37

38 Single Source Shortest Path complexity initialisation set all distances (s, v) to infinity (step.) (V) update all distances (s, v) routing through s (step.) (V) loop over all vertices find next vertex v (step 3.) (V) update all distances (s, v ) routing through v (step.) (V) repeat above steps V times total cost (V ) hence, DIJKSTRA belongs to class (V ) with quadratic runtime complexity optimised versions use a heap for choosing the minimum and, thus, have a complexity of ((E V) log (V)) variants: A ( informed DIJKSTRA using heuristics), BELLMANN FORD (allows negative edge weights), FLOYD WARSHALL (all pairs shortest path (APSP)) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 38

39 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 39

40 Transitive Closure fundamentals definition: some relation R V V is called transitive if for all vertices v, v, v Vwith v v and v v follows v v example: from 3 and 3 due to transitivity follows with R we denote the transitive closure of R that contains all pairs (v, v ) that are connected through R, i.e. there is (at least) one path from v to v in other words: R contains all paths in a directed graph, i.e. with v v and v v in R follows that v v is also included in R example v 3 v v 3 v 0 R R v v v v PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 0

41 Transitive Closure fundamentals (cont d) idea: a path exists between two vertices v i and v j if there is an edge from v i to v j, or a path from v i to v j through vertex v, or a path from v i to v j through vertex v and or v, or a path from v i to v j through vertex v, v and or v 3, or... more formal v i v v v 3 v j v i v k (v i, v j ) R(k) (v i, v j ) R (k ) (v i, v k ) R (k ) and (v k, v j ) R (k ) v j during k th iteration, the algorithm determines if a path between two vertices v i and v j exists using just vertices v m with m,..., k allowed as an intermediate PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

42 Transitive Closure WARSHALL algorithm previous recurrence (v i, v j ) R (k) (v i, v j ) R (k ) ((v i, v k ) R (k ) (v k, v j ) R (k ) ) leads to the following rules ) if an element r ij in R (k ), it remains in R (k) ) if an element r ij 0 in R (k ), it has to be changed to in R (k) if and only if both elements r ik and r kj in R (k ) j k j k R (k ) k R (k) k 0 i i PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

43 Transitive Closure WARSHALL algorithm (cont d) preliminary: directed graph G (V, E) stored as adjacency matrix A R (0) A for k to V do for i to V do for j to V do r(i, j) (k) r(i, j) (k ) (r(i, k) (k ) r(k, j) (k ) ) od od od what about complexity...? there are three nested loops over i, j, k obviously, WARSHALL belongs to class (V 3 ) and has a cubic runtime complexity, making it very slow for large adjacency matrices PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

44 Transitive Closure WARSHALL algorithm (cont d) example a b R (0) a b c d a b c a b R () a b c d a b c c d 0 0 d c d 0 0 d a b R () a b c d a b c a b R () a b c d a b c c d 0 d c d d R PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

45 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

46 Network Flow fundamentals let G (V, E) be a directed graph with two designated vertices s, t V, called source and sink, resp., as well as a capacity function c : V V, assigning each edge (v, v ) E a non negative capacity c(v, v ) we further assume, each vertex is reachable from source s network flow is a function f : V V that fulfils following properties. conservation of flow: for all vertices v V \ s, t holds. limitation of capacity: for all vertices v, v Vholds 0 f(v, v ) c(v, v ) hence, we define the total flow F : V V as or PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 6

47 Network Flow fundamentals (cont d) application: many questions can be modelled as flow problem assume, ports A,..., A p store bananas for shipping to ports B,..., B q r i with i,..., p denotes how many bananas are ready for shipping at A i d j with j,..., q denotes how many bananas are requested at port B j c(a i, B j ) with i,..., p and j,..., q denotes the capacity of bananas (in metric tons) that can be transported via route between ports A i and B j question. is it possible to satisfy all request. if not, how many tons can be transported at most to all destinations 3. how (i.e. on which route) should the bananas be shipped all questions above to be modelled as flow problem using a directed graph G (V, E) with V s, t, A,..., A p, B,..., B q PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 7

48 Network Flow fundamentals (cont d) sample graph for p 3 and q s r r A A c(a, B ) B d t let F : E A 3 be a total flow, thus previous question easily to be answered. all request can be satisfied if F. at most F tons of bananas can be transported to all destinations 3. flow f(a i, B j ) denotes how many tons are transported from A i to B j other flow problem example: can a soccer team (still) become champion according to the current position in the league and the remaining matches B d r 3 c(a 3, B ) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 8

49 Network Flow fundamentals (cont d) problem: how to find a flow f for which the total flow is maximum a partitioning of V into parts S V and T V is called cut with s S, t T, and T V \ S; let c(s, T) denote the capacity of the cut (S, T) defined as the flow f over a cut (S, T) is then defined as example s 3 T t obviously, capacity c(s, T) is an upper bound for the flow that can be sent from source to sink S c(s, T) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 9

50 Network Flow fundamentals (cont d) from previous observation, we can reason that the total flow can be measured at any arbitrary cut (S, T) and is bounded by c(s, T) F f(s, T) c(s, T) proof: with 0 f(e) c(e) for every edge e E follows () hence, if F and c(s, T) satisfy () by equality then F is maximum and the cut (S, T) is of minimum capacity remark: if F is maximum the flow cannot be further increased any algorithm for updating flows f(e) must halt termination is guaranteed PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 0

51 Network Flow FORD and FULKERSON algorithm task: compute for G (V, E) with capacities c : V V its total flow idea: find augmenting path from source to sink such that the flow along this path can be increased without exceeding capacity limitations algorithm proposed by L.R. FORD, JR. and D.R. FULKERSON in 96. initialise flow f(e) 0 for all e E. while augmenting path p (s v 0, v, v,..., v k t) i. increase flow f along p 3. compute total flow F definition: augmenting path The residual network G f (V, E f ) is defined on the same set of vertices V and on edges (v, v ) E f where (v, v ) E c f (v, v ) c(v, v ) f(v, v ) 0 or (v, v) E c f (v, v ) f(v, v) 0 holds. An augmenting path is a simple path from s to t in G f. PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

52 Network Flow FORD and FULKERSON algorithm (cont d) example 6 3 s t s t left: G with edge labelling a b denoting a f(e) and b c(e); right: residual network G f s 6 t s t two possible augmenting paths PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

53 Network Flow FORD and FULKERSON algorithm (cont d) finally, what means increasing flow along some augmenting path...? let p be a simple path from s to t within the residual network G f then, the flow along that path is increased f(v, v ) f(v, v ) f(v, v ) if (v, v ) E (v, v ) p if (v, v ) E (v, v) p f(v, v ) otherwise with note: if all capacities of G are integer values, then the total flow also is an integer value ( important property for some applications) PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 3

54 Network Flow FORD and FULKERSON algorithm (cont d) example: full processing of FFA (w/o explicit presentation of G f ) s v v t s v v t 0 7 v 3 v initial situation all flows f(e) v 3 v path s v v v 3 v t with s 6 v v t s 0 6 v 6 0 v t v v 3 path s v 3 v t with v v 3 path s v 3 v t with PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

55 Network Flow FORD and FULKERSON algorithm (cont d) example: full processing of FFA (w/o explicit presentation of G f ) s v v 0 v 3 v path s v v t with t complexity for any given flow residual network G f can be computed in (E) time any path from s to t in G f can be found in (E) time for integer capacities, the flow is increased at least by one during each iteration, thus the number of iterations is bounded by C hence, FFA has (E C) runtime complexity which grows for increasing E s v v 0 T S v 3 v no more augmenting path to be found total flow F t PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08

56 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 6

57 What Else...? travelling salesperson problem (TSP) formerly known as travelling salesman problem question: given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city Hamiltonian cycle source: Jessica Yu solution to 8 states travelling salesperson problem TSP is a combinatorial optimisation problem no algorithm can find the solution in polynomial worst case runtime PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 7

58 overview fundamentals minimum spanning tree (single source) shortest path transitive closure network flow what else...? PD Dr. Ralf Peter Mundani Algorithms and Data Structures Summer Term 08 8

Material handling and Transportation in Logistics. Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena

Material handling and Transportation in Logistics. Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena Material handling and Transportation in Logistics Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena Introduction to Graph Theory Graph Theory As Mathematical

More information

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation The Shortest Path Problem jla,jc@imm.dtu.dk Department of Management Engineering Technical University of Denmark The Shortest Path Problem Given a directed network G = (V,E,w) for which the underlying

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures Chapter 9 Graph s 2 Definitions Definitions an undirected graph is a finite set

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be if not careful with data structures 3 Definitions an undirected graph G = (V, E) is a

More information

6.2. Paths and Cycles

6.2. Paths and Cycles 6.2. PATHS AND CYCLES 85 6.2. Paths and Cycles 6.2.1. Paths. A path from v 0 to v n of length n is a sequence of n+1 vertices (v k ) and n edges (e k ) of the form v 0, e 1, v 1, e 2, v 2,..., e n, v n,

More information

Graph Algorithms. A Brief Introduction. 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ.

Graph Algorithms. A Brief Introduction. 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ. Graph Algorithms A Brief Introduction 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ. 目录 2015/5/7 1 Graph and Its Applications 2 Introduction to Graph Algorithms 3 References

More information

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design (8) Graph Algorithms 1/2 Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of

More information

Introduction III. Graphs. Motivations I. Introduction IV

Introduction III. Graphs. Motivations I. Introduction IV Introduction I Graphs Computer Science & Engineering 235: Discrete Mathematics Christopher M. Bourke cbourke@cse.unl.edu Graph theory was introduced in the 18th century by Leonhard Euler via the Königsberg

More information

Simple graph Complete graph K 7. Non- connected graph

Simple graph Complete graph K 7. Non- connected graph A graph G consists of a pair (V; E), where V is the set of vertices and E the set of edges. We write V (G) for the vertices of G and E(G) for the edges of G. If no two edges have the same endpoints we

More information

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)

More information

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is

More information

Graph Theory. Part of Texas Counties.

Graph Theory. Part of Texas Counties. Graph Theory Part of Texas Counties. We would like to visit each of the above counties, crossing each county only once, starting from Harris county. Is this possible? This problem can be modeled as a graph.

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no

More information

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms Introduction to Parallel & Distributed Computing Parallel Graph Algorithms Lecture 16, Spring 2014 Instructor: 罗国杰 gluo@pku.edu.cn In This Lecture Parallel formulations of some important and fundamental

More information

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS DR. ANDREW SCHWARTZ, PH.D. 10.1 Graphs and Graph Models (1) A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes)

More information

Artificial Intelligence

Artificial Intelligence Artificial Intelligence Shortest Path Problem G. Guérard Department of Nouvelles Energies Ecole Supérieur d Ingénieurs Léonard de Vinci Lecture 3 GG A.I. 1/42 Outline 1 The Shortest Path Problem Introduction

More information

Maximum flows & Maximum Matchings

Maximum flows & Maximum Matchings Chapter 9 Maximum flows & Maximum Matchings This chapter analyzes flows and matchings. We will define flows and maximum flows and present an algorithm that solves the maximum flow problem. Then matchings

More information

Varying Applications (examples)

Varying Applications (examples) Graph Theory Varying Applications (examples) Computer networks Distinguish between two chemical compounds with the same molecular formula but different structures Solve shortest path problems between cities

More information

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Graph Theory CS/Math231 Discrete Mathematics Spring2015 1 Graphs Definition 1 A directed graph (or digraph) G is a pair (V, E), where V is a finite set and E is a binary relation on V. The set V is called the vertex set of G, and its elements are called vertices

More information

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory SCHOOL OF ENGINEERING & BUILT ENVIRONMENT Mathematics An Introduction to Graph Theory. Introduction. Definitions.. Vertices and Edges... The Handshaking Lemma.. Connected Graphs... Cut-Points and Bridges.

More information

Parallel Graph Algorithms

Parallel Graph Algorithms Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050/VT3 Part I Introduction Overview Graphs definitions & representations Minimal Spanning Tree (MST) Prim s algorithm Single Source

More information

Classic Graph Theory Problems

Classic Graph Theory Problems Classic Graph Theory Problems Hiroki Sayama sayama@binghamton.edu The Origin Königsberg bridge problem Pregel River (Solved negatively by Euler in 176) Representation in a graph Can all the seven edges

More information

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs Introduction to Mathematical Programming IE406 Lecture 16 Dr. Ted Ralphs IE406 Lecture 16 1 Reading for This Lecture Bertsimas 7.1-7.3 IE406 Lecture 16 2 Network Flow Problems Networks are used to model

More information

Chapter 11: Graphs and Trees. March 23, 2008

Chapter 11: Graphs and Trees. March 23, 2008 Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a

More information

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck Theory of Computing Lecture 10 MAS 714 Hartmut Klauck Seven Bridges of Königsberg Can one take a walk that crosses each bridge exactly once? Seven Bridges of Königsberg Model as a graph Is there a path

More information

Konigsberg Bridge Problem

Konigsberg Bridge Problem Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at

More information

Index. stack-based, 400 A* algorithm, 325

Index. stack-based, 400 A* algorithm, 325 Index Abstract transitive closure, 174-175, 217-221 Active vertex, 411 Acyclic graph. See Digraph; Directed acyclic graph (DAG) Acyclic network, 313-321, 334-335 maxflow, 427-429 Adjacency-lists representation,

More information

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/z

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ -  artale/z CHAPTER 10 GRAPHS AND TREES Alessandro Artale UniBZ - http://www.inf.unibz.it/ artale/z SECTION 10.1 Graphs: Definitions and Basic Properties Copyright Cengage Learning. All rights reserved. Graphs: Definitions

More information

Reference Sheet for CO142.2 Discrete Mathematics II

Reference Sheet for CO142.2 Discrete Mathematics II Reference Sheet for CO14. Discrete Mathematics II Spring 017 1 Graphs Defintions 1. Graph: set of N nodes and A arcs such that each a A is associated with an unordered pair of nodes.. Simple graph: no

More information

CS 561, Lecture 9. Jared Saia University of New Mexico

CS 561, Lecture 9. Jared Saia University of New Mexico CS 561, Lecture 9 Jared Saia University of New Mexico Today s Outline Minimum Spanning Trees Safe Edge Theorem Kruskal and Prim s algorithms Graph Representation 1 Graph Definition A graph is a pair of

More information

Lecture 4: Graph Algorithms

Lecture 4: Graph Algorithms Lecture 4: Graph Algorithms Definitions Undirected graph: G =(V, E) V finite set of vertices, E finite set of edges any edge e = (u,v) is an unordered pair Directed graph: edges are ordered pairs If e

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 2018 Part 2: Data Structures PD Dr.

More information

Lecture 3: Totally Unimodularity and Network Flows

Lecture 3: Totally Unimodularity and Network Flows Lecture 3: Totally Unimodularity and Network Flows (3 units) Outline Properties of Easy Problems Totally Unimodular Matrix Minimum Cost Network Flows Dijkstra Algorithm for Shortest Path Problem Ford-Fulkerson

More information

CHAPTER 10 GRAPHS AND TREES. Copyright Cengage Learning. All rights reserved.

CHAPTER 10 GRAPHS AND TREES. Copyright Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES Copyright Cengage Learning. All rights reserved. SECTION 10.1 Graphs: Definitions and Basic Properties Copyright Cengage Learning. All rights reserved. Graphs: Definitions and

More information

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Chalmers University of Technology. Network Models. April 11, Birgit Grohe

Chalmers University of Technology. Network Models. April 11, Birgit Grohe Chalmers University of Technology Applied Optimisation lp 4 VT08 Network Models April 11, 2008 Birgit Grohe Network Models - Examples Many different problems can be formulated as graph/network models:

More information

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019 CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction

More information

Minimum Cost Edge Disjoint Paths

Minimum Cost Edge Disjoint Paths Minimum Cost Edge Disjoint Paths Theodor Mader 15.4.2008 1 Introduction Finding paths in networks and graphs constitutes an area of theoretical computer science which has been highly researched during

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

2.3 Optimal paths. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

2.3 Optimal paths. E. Amaldi Foundations of Operations Research Politecnico di Milano 1 . Optimal paths E. Amaldi Foundations of Operations Research Politecnico di Milano Optimal (minimum or maximum) paths have a wide range of applications: Google maps, GPS navigators planning and management

More information

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies: UNIT 5 CSE 103 - Unit V- Graph GRAPH Graph is another important non-linear data structure. In tree Structure, there is a hierarchical relationship between, parent and children that is one-to-many relationship.

More information

Minimum Spanning Trees Shortest Paths

Minimum Spanning Trees Shortest Paths Minimum Spanning Trees Shortest Paths Minimum Spanning Tree Given a set of locations, with positive distances to each other, we want to create a network that connects all nodes to each other with minimal

More information

2.3 Optimal paths. Optimal (shortest or longest) paths have a wide range of applications:

2.3 Optimal paths. Optimal (shortest or longest) paths have a wide range of applications: . Optimal paths Optimal (shortest or longest) paths have a wide range of applications: Google maps, GPS navigators planning and management of transportation, electrical and telecommunication networks project

More information

Shortest Path Problem

Shortest Path Problem Shortest Path Problem CLRS Chapters 24.1 3, 24.5, 25.2 Shortest path problem Shortest path problem (and variants) Properties of shortest paths Algorithmic framework Bellman-Ford algorithm Shortest paths

More information

Theorem 2.9: nearest addition algorithm

Theorem 2.9: nearest addition algorithm There are severe limits on our ability to compute near-optimal tours It is NP-complete to decide whether a given undirected =(,)has a Hamiltonian cycle An approximation algorithm for the TSP can be used

More information

Source. Sink. Chapter 10: Iterative Programming Maximum Flow Problem. CmSc250 Intro to Algorithms

Source. Sink. Chapter 10: Iterative Programming Maximum Flow Problem. CmSc250 Intro to Algorithms Chapter 10: Iterative Programming Maximum Flow Problem CmSc20 Intro to Algorithms A flow network is a model of a system where some material is produced at its source, travels through the system, and is

More information

Jessica Su (some parts copied from CLRS / last quarter s notes)

Jessica Su (some parts copied from CLRS / last quarter s notes) 1 Max flow Consider a directed graph G with positive edge weights c that define the capacity of each edge. We can identify two special nodes in G: the source node s and the sink node t. We want to find

More information

Single Source Shortest Path (SSSP) Problem

Single Source Shortest Path (SSSP) Problem Single Source Shortest Path (SSSP) Problem Single Source Shortest Path Problem Input: A directed graph G = (V, E); an edge weight function w : E R, and a start vertex s V. Find: for each vertex u V, δ(s,

More information

Network Models - Examples. Network Models. Definition and Terminology. The Minimum Spanning Tree (MST) Problem

Network Models - Examples. Network Models. Definition and Terminology. The Minimum Spanning Tree (MST) Problem Chalmers University of Technology Applied Optimisa- Network Models - Examples tion lp 4 VT08 Network Models April 11, 2008 Birgit Grohe Many different problems can be formulated as graph/network models:

More information

Basics of Graph Theory

Basics of Graph Theory Basics of Graph Theory 1 Basic notions A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Simple graphs have their

More information

CS 4407 Algorithms Lecture 5: Graphs an Introduction

CS 4407 Algorithms Lecture 5: Graphs an Introduction CS 4407 Algorithms Lecture 5: Graphs an Introduction Prof. Gregory Provan Department of Computer Science University College Cork 1 Outline Motivation Importance of graphs for algorithm design applications

More information

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7 CS 70 Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7 An Introduction to Graphs A few centuries ago, residents of the city of Königsberg, Prussia were interested in a certain problem.

More information

Notes on Minimum Cuts and Modular Functions

Notes on Minimum Cuts and Modular Functions Notes on Minimum Cuts and Modular Functions 1 Introduction The following are my notes on Cunningham s paper [1]. Given a submodular function f and a set S, submodular minimisation is the problem of finding

More information

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed. CS490 Quiz 1 NAME: STUDENT NO: SIGNATURE: This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed. Not all questions are of the same

More information

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia) 15-251 Great Ideas in Theoretical Computer Science Lecture 12: Graphs I: The Basics February 22nd, 2018 Crossing bridges Königsberg (Prussia) Now Kaliningrad (Russia) Is there a way to walk through the

More information

Discrete mathematics II. - Graphs

Discrete mathematics II. - Graphs Emil Vatai April 25, 2018 Basic definitions Definition of an undirected graph Definition (Undirected graph) An undirected graph or (just) a graph is a triplet G = (ϕ, E, V ), where V is the set of vertices,

More information

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs Graphs and Network Flows IE411 Lecture 21 Dr. Ted Ralphs IE411 Lecture 21 1 Combinatorial Optimization and Network Flows In general, most combinatorial optimization and integer programming problems are

More information

Introduction to Graph Theory

Introduction to Graph Theory Introduction to Graph Theory Tandy Warnow January 20, 2017 Graphs Tandy Warnow Graphs A graph G = (V, E) is an object that contains a vertex set V and an edge set E. We also write V (G) to denote the vertex

More information

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8 Fundamental Algorithms CSCI-GA.70-00/Summer 206 Solution to Homework 8 Problem (CLRS 23.-6). ( point) Show that a graph has a unique minimum spanning tree if, for every cut of the graph, there is a unique

More information

Graphs and Network Flows IE411. Lecture 13. Dr. Ted Ralphs

Graphs and Network Flows IE411. Lecture 13. Dr. Ted Ralphs Graphs and Network Flows IE411 Lecture 13 Dr. Ted Ralphs IE411 Lecture 13 1 References for Today s Lecture IE411 Lecture 13 2 References for Today s Lecture Required reading Sections 21.1 21.2 References

More information

CS 4349 Lecture October 23rd, 2017

CS 4349 Lecture October 23rd, 2017 CS 4349 Lecture October 23rd, 2017 Main topics for #lecture include #minimum_spanning_trees and #SSSP. Prelude Homework 7 due Wednesday, October 25th. Don t forget about the extra credit. Minimum Spanning

More information

V1.0: Seth Gilbert, V1.1: Steven Halim August 30, Abstract. d(e), and we assume that the distance function is non-negative (i.e., d(x, y) 0).

V1.0: Seth Gilbert, V1.1: Steven Halim August 30, Abstract. d(e), and we assume that the distance function is non-negative (i.e., d(x, y) 0). CS4234: Optimisation Algorithms Lecture 4 TRAVELLING-SALESMAN-PROBLEM (4 variants) V1.0: Seth Gilbert, V1.1: Steven Halim August 30, 2016 Abstract The goal of the TRAVELLING-SALESMAN-PROBLEM is to find

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Lecture 6 Basic Graph Algorithms

Lecture 6 Basic Graph Algorithms CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 6 Basic Graph Algorithms Uttam Thakore University of Illinois at Urbana-Champaign September 30, 2015 Updates ICPC Regionals teams will be

More information

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn Graphs Extremely important concept in computer science Graph, : node (or vertex) set : edge set Simple graph: no self loops, no multiple

More information

Solving problems on graph algorithms

Solving problems on graph algorithms Solving problems on graph algorithms Workshop Organized by: ACM Unit, Indian Statistical Institute, Kolkata. Tutorial-3 Date: 06.07.2017 Let G = (V, E) be an undirected graph. For a vertex v V, G {v} is

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that

More information

Euler and Hamilton paths. Jorge A. Cobb The University of Texas at Dallas

Euler and Hamilton paths. Jorge A. Cobb The University of Texas at Dallas Euler and Hamilton paths Jorge A. Cobb The University of Texas at Dallas 1 Paths and the adjacency matrix The powers of the adjacency matrix A r (with normal, not boolean multiplication) contain the number

More information

Lecture 3: Graphs and flows

Lecture 3: Graphs and flows Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected

More information

GRAPH DECOMPOSITION BASED ON DEGREE CONSTRAINTS. March 3, 2016

GRAPH DECOMPOSITION BASED ON DEGREE CONSTRAINTS. March 3, 2016 GRAPH DECOMPOSITION BASED ON DEGREE CONSTRAINTS ZOÉ HAMEL March 3, 2016 1. Introduction Let G = (V (G), E(G)) be a graph G (loops and multiple edges not allowed) on the set of vertices V (G) and the set

More information

Chapter 1 Graph Theory

Chapter 1 Graph Theory Chapter Graph Theory - Representations of Graphs Graph, G=(V,E): It consists of the set V of vertices and the set E of edges. If each edge has its direction, the graph is called the directed graph (digraph).

More information

DESIGN AND ANALYSIS OF ALGORITHMS

DESIGN AND ANALYSIS OF ALGORITHMS DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.

More information

Shortest path problems

Shortest path problems Next... Shortest path problems Single-source shortest paths in weighted graphs Shortest-Path Problems Properties of Shortest Paths, Relaxation Dijkstra s Algorithm Bellman-Ford Algorithm Shortest-Paths

More information

Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms. 11. Graphs and Trees 1. Aaron Tan. 30 October 3 November 2017

Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms. 11. Graphs and Trees 1. Aaron Tan. 30 October 3 November 2017 11. Graphs and Trees 1 Aaron Tan 30 October 3 November 2017 1 The origins of graph theory are humble, even frivolous. Whereas many branches of mathematics were motivated by fundamental problems of calculation,

More information

Introduction to Graphs

Introduction to Graphs Introduction to Graphs Historical Motivation Seven Bridges of Königsberg Königsberg (now Kaliningrad, Russia) around 1735 Problem: Find a walk through the city that would cross each bridge once and only

More information

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list UNIT-4 Graph: Terminology, Representation, Traversals Applications - spanning trees, shortest path and Transitive closure, Topological sort. Sets: Representation - Operations on sets Applications. 1. Name

More information

from notes written mostly by Dr. Carla Savage: All Rights Reserved

from notes written mostly by Dr. Carla Savage: All Rights Reserved CSC 505, Fall 2000: Week 9 Objectives: learn about various issues related to finding shortest paths in graphs learn algorithms for the single-source shortest-path problem observe the relationship among

More information

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University

Algorithms. All-Pairs Shortest Paths. Dong Kyue Kim Hanyang University Algorithms All-Pairs Shortest Paths Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr Contents Using single source shortest path algorithms Presents O(V 4 )-time algorithm, O(V 3 log V)-time algorithm,

More information

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory Math.3336: Discrete Mathematics Chapter 10 Graph Theory Instructor: Dr. Blerina Xhabli Department of Mathematics, University of Houston https://www.math.uh.edu/ blerina Email: blerina@math.uh.edu Fall

More information

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1 Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching

More information

CS 6783 (Applied Algorithms) Lecture 5

CS 6783 (Applied Algorithms) Lecture 5 CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)

More information

Shortest Paths. March 21, CTU in Prague. Z. Hanzálek (CTU) Shortest Paths March 21, / 44

Shortest Paths. March 21, CTU in Prague. Z. Hanzálek (CTU) Shortest Paths March 21, / 44 Shortest Paths Zdeněk Hanzálek hanzalek@fel.cvut.cz CTU in Prague March 21, 2017 Z. Hanzálek (CTU) Shortest Paths March 21, 2017 1 / 44 Table of contents 1 Introduction Problem Statement Negative Weights

More information

Graph theory: basic concepts

Graph theory: basic concepts Graph theory: basic concepts Graphs and networks allow modelling many different decision problems Graphs permit to represent relationships among different kinds of entities: Cities connected by roads Computers

More information

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS 1 UNIT I INTRODUCTION CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS 1. Define Graph. A graph G = (V, E) consists

More information

Lecture 10 Graph Algorithms

Lecture 10 Graph Algorithms Lecture 10 Graph Algorithms Euiseong Seo (euiseong@skku.edu) 1 Graph Theory Study of the properties of graph structures It provides us with a language with which to talk about graphs Keys to solving problems

More information

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

More NP-complete Problems. CS255 Chris Pollett May 3, 2006. More NP-complete Problems CS255 Chris Pollett May 3, 2006. Outline More NP-Complete Problems Hamiltonian Cycle Recall a hamiltonian cycle is a permutation of the vertices v i_1,, v i_n of a graph G so

More information

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502) Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik Combinatorial Optimization (MA 4502) Dr. Michael Ritter Problem Sheet 4 Homework Problems Problem

More information

Analysis of Algorithms, I

Analysis of Algorithms, I Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, March 8, 2016 Outline 1 Recap Single-source shortest paths in graphs with real edge weights:

More information

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV Sr.No. Question Option A Option B Option C Option D 1 2 3 4 5 6 Class : S.E.Comp Which one of the following is the example of non linear data structure Let A be an adjacency matrix of a graph G. The ij

More information

looking ahead to see the optimum

looking ahead to see the optimum ! Make choice based on immediate rewards rather than looking ahead to see the optimum! In many cases this is effective as the look ahead variation can require exponential time as the number of possible

More information

Single Source Shortest Path

Single Source Shortest Path Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Graphs : Shortest Paths Marius Kloft Content of this Lecture Single-Source-Shortest-Paths: Dijkstra s Algorithm Single-Source-Single-Target All-Pairs Shortest Paths Transitive

More information

8. The Postman Problems

8. The Postman Problems 8. The Postman Problems The Chinese postman problem (CPP) A postal carrier must pick up the mail at the post office, deliver the mail along blocks on the route, and finally return to the post office. To

More information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Communication Speeds in a Computer Network Find fastest way to route a data packet between two computers 6 Kbps 4 0 Mbps 6 6 Kbps 6 Kbps Gbps 00 Mbps 8 6 Kbps

More information

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees. Tree 1. Trees and their Properties. Spanning trees 3. Minimum Spanning Trees 4. Applications of Minimum Spanning Trees 5. Minimum Spanning Tree Algorithms 1.1 Properties of Trees: Definition: A graph G

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur Lecture : Graphs Rajat Mittal IIT Kanpur Combinatorial graphs provide a natural way to model connections between different objects. They are very useful in depicting communication networks, social networks

More information

Elements of Graph Theory

Elements of Graph Theory Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered

More information

Shortest Paths. Nishant Mehta Lectures 10 and 11

Shortest Paths. Nishant Mehta Lectures 10 and 11 Shortest Paths Nishant Mehta Lectures 0 and Finding the Fastest Way to Travel between Two Intersections in Vancouver Granville St and W Hastings St Homer St and W Hastings St 6 Granville St and W Pender

More information

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m Minimum Spanning Trees (MST) 8 0 e 7 b 3 a 5 d 9 h i g c 8 7 6 3 f j 9 6 k l 5 m A graph H(U,F) is a subgraph of G(V,E) if U V and F E. A subgraph H(U,F) is called spanning if U = V. Let G be a graph with

More information