Undirected graph is a special case of a directed graph, with symmetric edges

Size: px
Start display at page:

Download "Undirected graph is a special case of a directed graph, with symmetric edges"

Transcription

1 ijkstra s lgorithm 7-: omputing iven a directed weighted graph(all weights non-negative) and two verticesxand y, find the least-cost path fromxtoy in. Undirected graph is a special case of a directed graph, with symmetric edges Least-cost path may not be the path containing the fewest edges shortest path == least cost path path containing fewest edges = path containing fewest edges 7-: xample Shortest path path containing fewest edges 8 from to? 7-: xample Shortest path path containing fewest edges 8 from to :,,,, 7-: Single Source

2 ijkstra s lgorithm To find the shortest path from vertex x to vertex y, we need (worst case) to find the shortest path from x to all other vertices in the graph Why? 7-: Single Source To find the shortest path from vertex x to vertex y, we need (worst case) to find the shortest path from x to all other vertices in the graph To find the shortest path fromx toy, we need to find the shortest path fromxto all nodes on the path from x to y Worst case, all nodes will be on the path 7-: Single Source If all edges have unit weight : Single Source If all edges have unit weight, We can use readth irst Search to compute the shortest path S Spanning Tree contains shortest path to each node in the graph Need to do some more work to create & save S spanning tree When edges have differing weights, this obviously will not work 7-7: Single Source ivide the vertices into two sets: Vertices whose shortest path from the initial vertex is known Vertices whose shortest path from the initial vertex is not known Initially, only the initial vertex is known Move vertices one at a time from the unknown set to the known set, until all vertices are known 7-8: Single Source 8 6

3 ijkstra s lgorithm Start with the vertex 7-9: Single Source 8 6 Known vertices are circled in red We can now extend the known set by vertex 7-: Single Source 8 6 Why is it safe to add, with cost? 7-: Single Source 8 6 Why is it safe to add, with cost? istance istance istance

4 ijkstra s lgorithm ould we do better with a more roundabout path? 7-: Single Source 8 6 istance Why is it safe to add, with cost? ould we do better with a more roundabout path? No to get to any other node will cost at least No negative edge weights, can t do better than 7-: Single Source 8 6 istance We can now add another vertex to our known list... 7-: Single Source 8 6 istance How do we know that we could not get to cheaper than by going through?

5 ijkstra s lgorithm 7-: Single Source 8 6 istance How do we know that we could not get to cheaper than by going through? osts to get to osts at least to get anywhere from ost at least (+ = ) to get to through 7-6: Single Source 8 6 Next node we can add... istance 7-7: Single Source 8 6 (We also could have added for this step) Next vertex to add to Known... istance

6 ijkstra s lgorithm 6 7-8: Single Source 8 6 ost to add is 8 (through ) ost to add is (through ) istance 7-9: Single Source 8 6 istance Last node... 7-: Single Source 8 6 istance 6 We now know the length of the shortest path fromto all other vertices in the graph 7-: ijkstra s lgorithm

7 ijkstra s lgorithm 7 Keep a table that contains, for each vertex Is the distance to that vertex known? What is the best distance we ve found so far? Repeat: Pick the smallest unknown distance mark it as known update the distance of all unknown neighbors of that node Until all vertices are known 7-: ijkstra s lgorithm xample 7 7-: ijkstra s lgorithm xample 7 7-: ijkstra s lgorithm xample 7 7 Known istance false false false false false false Known istance true false 7 false false false false

8 ijkstra s lgorithm : ijkstra s lgorithm xample 7 7-6: ijkstra s lgorithm xample 7 7-7: ijkstra s lgorithm xample Known istance true false 7 false false 8 false true Known istance true false 7 false false 8 true true Known istance true false true false 6 true true

9 ijkstra s lgorithm : ijkstra s lgorithm xample 7 Known istance true true true false 6 true true : ijkstra s lgorithm Known istance true true true true 6 true true fter ijkstra s algorithm is complete: We know the length of the shortest path We do not know what the shortest path is How can we modify ijstra s algorithm to compute the path? 7-: ijkstra s lgorithm fter ijkstra s algorithm is complete: We know the length of the shortest path We do not know what the shortest path is How can we modify ijstra s algorithm to compute the path? Store not only the distance, but the immediate parent that led to this distance

10 ijkstra s lgorithm 7-: ijkstra s lgorithm xample 7-: ijkstra s lgorithm xample 7-: ijkstra s lgorithm xample 7-: ijkstra s lgorithm xample 7-: ijkstra s lgorithm xample Known ist Path false false false false false false false Known ist Path true false false false false false false Known ist Path true false true false false false false Known ist Path true false true true false 9 false 9 false 7

11 ijkstra s lgorithm 7-6: ijkstra s lgorithm xample 7-7: ijkstra s lgorithm xample 7-8: ijkstra s lgorithm xample 7-9: ijkstra s lgorithm Known ist Path true true true true false 9 false 9 false 7 Known ist Path true true true true false 9 false 8 true 7 Known ist Path true true true true false 9 true 8 true 7 Known ist Path true true true true true 9 true 8 true 7 iven the path field, we can construct the shortest path Work backward from the end of the path

12 ijkstra s lgorithm ollow the path pointers until the start node is reached 7-: ijkstra ode We can use a sentinel value in the path field of the initial node, so we know when to stop void ijkstra(dge [], int s, tablentry T[]) { int i, v; dge e; for(i=; i<.length; i++) { T[i].distance = Integer.MX_VLU; T[i].path = -; T[i].known = false; T[s].distance = ; for (i=; i <.length; i++) { v = minunknownvertex(t); T[v].known = true; for (e = [v]; e!= null; e = e.next) { if (T[e.neighbor].distance > T[v].distance + e.cost) { T[e.neighbor].distance = T[v].distance + e.cost; T[e.neighbor].path = v; 7-: minunknownvertex alculating minimum distance unknown vertex: int minunknownvertex(tablentry T[]) { int i; int minvertex = -; int ministance = Integer.MX_VLU; for (i=; i < T.length; i++) { if ((!T[i].known) && (T[i].distance < Ministance)) { minvertex = i; ministance = T[i].distance; return minvertex; 7-: ijkstra Running Time Time for initialization: for(i=; i<.length; i++) { T[i].distance = Integer.MX_VLU; T[i].path = -; T[i].known = false; T[s].distance = ; 7-: ijkstra Running Time Time for initialization: for(i=; i<.length; i++) { T[i].distance = Integer.MX_VLU; T[i].path = -; T[i].known = false; T[s].distance = ;

13 ijkstra s lgorithm Θ(V) 7-: ijkstra Running Time Total time for all calls to minunknownvertex, and setting T[v].known = true (for all iterations of the loop) for (i=; i <.length; i++) { v = minunknownvertex(t); < These two lines T[v].known = true; < for (e = [v]; e!= null; e = e.next) { if (T[e.neighbor].distance > T[v].distance + e.cost) { T[e.neighbor].distance = T[v].distance + e.cost; T[e.neighbor].path = v; 7-: ijkstra Running Time Total time for all calls to minunknownvertex, and setting T[v].known = true (for all iterations of the loop) for (i=; i <.length; i++) { v = minunknownvertex(t); < These two lines T[v].known = true; < for (e = [v]; e!= null; e = e.next) { if (T[e.neighbor].distance > T[v].distance + e.cost) { T[e.neighbor].distance = T[v].distance + e.cost; T[e.neighbor].path = v; Θ(V ) 7-6: ijkstra Running Time Total # of times the if statement will be executed: for (i=; i <.length; i++) { v = minunknownvertex(t); T[v].known = true; for (e = [v]; e!= null; e = e.next) { > if (T[e.neighbor].distance > > T[v].distance + e.cost) { > T[e.neighbor].distance = T[v].distance + e.cost; > T[e.neighbor].path = v; 7-7: ijkstra Running Time Total # of times the if statement will be executed: for (i=; i <.length; i++) { v = minunknownvertex(t); T[v].known = true; for (e = [v]; e!= null; e = e.next) { > if (T[e.neighbor].distance > > T[v].distance + e.cost) { > T[e.neighbor].distance = T[v].distance + e.cost; > T[e.neighbor].path = v; 7-8: ijkstra Running Time Total running time for all iterations of the inner for statement:

14 ijkstra s lgorithm for (i=; i <.length; i++) { v = minunknownvertex(t); T[v].known = true; > for (e = [v]; e!= null; e = e.next) { > if (T[e.neighbor].distance > > T[v].distance + e.cost) { > T[e.neighbor].distance = T[v].distance + e.cost; > T[e.neighbor].path = v; 7-9: ijkstra Running Time Total running time for all iterations of the inner for statement: for (i=; i <.length; i++) { v = minunknownvertex(t); T[v].known = true; > for (e = [v]; e!= null; e = e.next) { > if (T[e.neighbor].distance > > T[v].distance + e.cost) { > T[e.neighbor].distance = T[v].distance + e.cost; > T[e.neighbor].path = v; Θ(V +) WhyΘ(V +) and not justθ()? 7-: ijkstra Running Time Total running time: Sum of: Time for initialization Time for executing all calls tominunknownvertex Time for executing all distance / path updates =Θ(V +V +(V +)) = Θ(V ) 7-: Improving ijkstra an we do better thanθ(v ) or dense graphs, we can t do better To ensure that the shortest path to all vertices is computed, need to look at all edges in the graph dense graph can haveθ(v ) edges or sparse graphs, we can do better Where should we focus our attention? 7-: Improving ijkstra an we do better thanθ(v ) or dense graphs, we can t do better To ensure that the shortest path to all vertices is computed, need to look at all edges in the graph dense graph can haveθ(v ) edges

15 ijkstra s lgorithm or sparse graphs, we can do better Where should we focus our attention? inding the unknown vertex with minimum cost! 7-: Improving ijkstra To improve the running time of ijkstra: Place all of the vertices on a min-heap Key value for min-heap = distance of vertex from initial While min-heap is not empty: Pop smallest value off min-heap Update table Problems with this method? 7-: Improving ijkstra To improve the running time of ijkstra: Place all of the vertices on a min-heap Key value for min-heap = distance of vertex from initial While min-heap is not empty: Pop smallest value off min-heap Update table Problems with this method? When we update the table, we need to rearrange the heap 7-: Rearranging the heap Store a pointer for each vertex back into the heap When we update the table, we need to do a decrease-key operation ecrease-key can take up to time O(lgV). (xamples!) 7-6: Rearranging the heap Total time: O(V)remove-mins O(V lgv) O() dercrease-keys O( lg V) Total time: O(V lgv +lgv) O(lgV) 7-7: Improving ijkstra Store vertices in heap When we update the table, we need to rearrange the heap

16 ijkstra s lgorithm 6 lternate Solution: When the cost of a vertex decreases, add a new copy to the heap 7-8: Improving ijkstra reate a new priority queue, add start node While the queue is not empty: Remove the vertexv with the smallest distance in the heap Ifv is not known Markv as known or each neigborw ofv If distance[w] distance[v] + cost((v,w)) Set distance[w] = distance[v] + cost((v,w)) dd w to priority queue with priority distance[w] 7-9: Improved ijkstra Time ach vertex can be added to the heap once for each incoming edge Size of the heap can then be up toθ() inserts, on heap that can be up to size delete-mins, on heap that can be upto to size Total: Θ(lg) Θ(lgV) 7-6: Improved? ijkstra Time on t use priority queue, running time isθ(v ) o use a prioroty queue, running time isθ(lg) Which is better? 7-6: Improved? ijkstra Time on t use priority queue, running time isθ(v ) o use a prioroty queue, running time isθ(lg) Which is better? or dense graphs, ( Θ(V )),Θ(V ) is better or sparse graphs ( Θ(V)), Θ( lg ) is better 7-6: Improved! ijkstra Time If we use a data structre called a ibonacci heap instead of a standard heap, we can implement decrease-key in constant time (on average). Total time: O(V)remove-mins O(V lgv)

17 ijkstra s lgorithm 7 O() dercrease-keys O() (each decrease key takes O() on average) Total time: O(V lgv +) 7-6: Negative dges What if our graph has negative-weight edges? Think of the cost of the edge as the amount of energy consumed for a segment of road downhill segment could have negative energy consumed for a hybrid Will ijkstra s algorithm still work correctly? xamples 7-6: Negative dges What happens if there is a negative-weight cycle? What does the shortest path even mean? 7-6: Negative dges What happens if there is a negative-weight cycle? What does the shortest path even mean? inding shortest paths in graphs that contain negative edges, assume that there are no negative weight cycles Hybrid example 7-66: ll-source What if we want to find the shortest path from all vertices to all other vertices? How can we do it? 7-67: ll-source What if we want to find the shortest path from all vertices to all other vertices? How can we do it? Run ijktra s lgorithmv times How long will this take? What about negative edges? 7-68: ll-source What if we want to find the shortest path from all vertices to all other vertices? How can we do it? Run ijktra s lgorithmv times How long will this take? Θ(Vlg) (using priority queue)

18 ijkstra s lgorithm 8 for sparse graphs,θ(v lgv) for dense graphs,θ(v lgv) Θ(V ) (not using a priority queue) What about negative edges? 7-69: loyd s lgorithm oesn t work correctly lternate solution to all pairs shortest path YieldsΘ(V ) running time for all graphs Works for graphs with negative edges an detect negative-weight cycles 7-7: loyd s lgorithm Vertices numbered from..(n-) k-path from vertex v to vertex u is a path whose intermediate vertices (other than v and u) contain only vertices numbered less than or equal tok --path is a direct link 7-7: k-path xamples 7 Shortest --path from to : Shortest -path from to : Shortest -path from to : Shortest -path from to : Shortest -path from to : 7-7: k-path xamples 7

19 ijkstra s lgorithm 9 Shortest --path from to : 7 Shortest -path from to : 7 Shortest -path from to : 6 Shortest -path from to : 6 Shortest -path from to : 6 Shortest -path from to : 7-7: loyd s lgorithm Shortestn-path = Shortest path Shortest --path: if there is no direct link ost of the direct link, otherwise 7-7: loyd s lgorithm Shortestn-path = Shortest path Shortest --path: if there is no direct link ost of the direct link, otherwise If we could use the shortestk-path to find the shortest(k +) path, we would be set 7-7: loyd s lgorithm Shortest k-path from v to u either goes through vertex k, or it does not If not: If so: Shortestk-path = shortest(k )-path Shortestk-path = shortestk path fromv to k, followed by the shortestk path fromk tow 7-76: loyd s lgorithm If we had the shortestk-path for all pairs (v,w), we could obtain the shortest k +-path for all pairs or each pairv,w, compare: length of thek-path fromv to w length of thek-path fromv to k appended to the k-path fromk tow Set thek+ path fromv tow to be the minimum of the two paths above 7-77: loyd s lgorithm Let k [v,w] be the length of the shortestk-path fromv to w.

20 ijkstra s lgorithm [v,w] = cost of arc fromv to w ( if no direct link) k [v,w] = MIN( k [v,w], k [v,k]+ k [k,w]) reate, use to create, use to create, and so on until we have n 7-78: loyd s lgorithm Use a doubly-nested loop to create k from k Use the same array to store k and k just overwrite with the new values mbed this loop in a loop from..k 7-79: loyd s lgorithm loyd(dge [], int [][]) { int i,j,k Initialize, [i][j] = cost from i to j for (k=; k<.length; k++; for(i=; i<.length; i++) for(j=; j<.length; j++) if (([i][k]!= Integer.MX_VLU) && ([k][j]!= Integer.MX_VLU) && ([i][j] > ([i,k] + [k,j]))) [i][j] = [i][k] + [k][j] 7-8: loyd s lgorithm We ve only calculated the distance of the shortest path, not the path itself We can use a similar strategy to the PTH field for ijkstra to store the path We will need a - array to store the paths: P[i][j] = last vertex on shortest path from i to j

Undirected graph is a special case of a directed graph, with symmetric edges

Undirected graph is a special case of a directed graph, with symmetric edges S-6S- ijkstra s lgorithm -: omputing iven a directed weighted graph (all weights non-negative) and two vertices x and y, find the least-cost path from x to y in. Undirected graph is a special case of a

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS45-05S-7 Shortest Path Dijkstra s Algorithm David Galles Department of Computer Science University of San Francisco 7-0: Computing Shortest Path Given a directed weighted

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2015S-18 Spanning Trees David Galles Department of Computer Science University of San Francisco 18-0: Spanning Trees Given a connected, undirected graph G A subgraph

More information

Lecture 13: Weighted Shortest Paths. These slides include material originally prepared by Dr. Ron Cytron and Dr. Steve Cole.

Lecture 13: Weighted Shortest Paths. These slides include material originally prepared by Dr. Ron Cytron and Dr. Steve Cole. Lecture : Weighted Shortest Paths These slides include material originally prepared by r. Ron ytron and r. Steve ole. nnouncements Lab code and post-lab due tonight Lab released tomorrow ijkstra s algorithm

More information

Minimum Spanning Trees and Shortest Paths

Minimum Spanning Trees and Shortest Paths Minimum Spanning Trees and Shortest Paths Prim's algorithm ijkstra's algorithm November, 017 inda eeren / eoffrey Tien 1 Recall: S spanning tree Starting from vertex 16 9 1 6 10 13 4 3 17 5 11 7 16 13

More information

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP) Spanning Tree (015) Lecture1: Graph III ohyung Han S, POSTH bhhan@postech.ac.kr efinition and property Subgraph that contains all vertices of the original graph and is a tree Often, a graph has many different

More information

Minimum Spanning Trees and Shortest Paths

Minimum Spanning Trees and Shortest Paths Minimum Spanning Trees and Shortest Paths Kruskal's lgorithm Prim's lgorithm Shortest Paths pril 04, 018 inda eeren / eoffrey Tien 1 Kruskal's algorithm ata types for implementation Kruskalslgorithm()

More information

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014 epartment of omputer Science Virginia Tech lacksburg, Virginia opyright c 04 by lifford. Shaffer : Theory of lgorithms Title page : Theory of lgorithms lifford. Shaffer Spring 04 lifford. Shaffer epartment

More information

CAD Algorithms. Shortest Path

CAD Algorithms. Shortest Path lgorithms Shortest Path lgorithms Mohammad Tehranipoor epartment September 00 Shortest Path Problem: ind the best way of getting from s to t where s and t are vertices in a graph. est: Min (sum of the

More information

Problem: Large Graphs

Problem: Large Graphs S : ata Structures raph lgorithms raph Search Lecture Problem: Large raphs It is expensive to find optimal paths in large graphs, using S or ijkstra s algorithm (for weighted graphs) How can we search

More information

Introduction to Graphs. common/notes/ppt/

Introduction to Graphs.   common/notes/ppt/ Introduction to Graphs http://people.cs.clemson.edu/~pargas/courses/cs212/ common/notes/ppt/ Introduction Graphs are a generalization of trees Nodes or verticies Edges or arcs Two kinds of graphs irected

More information

CSE 326: Data Structures Dijkstra s Algorithm. James Fogarty Autumn 2007

CSE 326: Data Structures Dijkstra s Algorithm. James Fogarty Autumn 2007 SE 6: Data Structures Dijkstra s lgorithm James Fogarty utumn 007 Dijkstra, Edsger Wybe Legendary figure in computer science; was a professor at University of Texas. Supported teaching introductory computer

More information

An Early Problem in Graph Theory. Clicker Question 1. Konigsberg and the River Pregel

An Early Problem in Graph Theory. Clicker Question 1. Konigsberg and the River Pregel raphs Topic " Hopefully, you've played around a bit with The Oracle of acon at Virginia and discovered how few steps are necessary to link just about anybody who has ever been in a movie to Kevin acon,

More information

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014

CS 5114: Theory of Algorithms. Graph Algorithms. A Tree Proof. Graph Traversals. Clifford A. Shaffer. Spring 2014 epartment of omputer Science Virginia Tech lacksburg, Virginia opyright c 04 by lifford. Shaffer : Theory of lgorithms Title page : Theory of lgorithms lifford. Shaffer Spring 04 lifford. Shaffer epartment

More information

An Early Problem in Graph Theory

An Early Problem in Graph Theory raphs Topic 2 " Hopefully, you've played around a bit with The Oracle of acon at Virginia and discovered how few steps are necessary to link just about anybody who has ever been in a movie to Kevin acon,

More information

Spanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS

Spanning Trees. CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Motivation. Observations. Spanning tree via DFS Spanning Trees S: ata Structures & lgorithms Lecture : Minimum Spanning Trees simple problem: iven a connected undirected graph =(V,), find a minimal subset of edges such that is still connected graph

More information

L10 Graphs. Alice E. Fischer. April Alice E. Fischer L10 Graphs... 1/37 April / 37

L10 Graphs. Alice E. Fischer. April Alice E. Fischer L10 Graphs... 1/37 April / 37 L10 Graphs lice. Fischer pril 2016 lice. Fischer L10 Graphs... 1/37 pril 2016 1 / 37 Outline 1 Graphs efinition Graph pplications Graph Representations 2 Graph Implementation 3 Graph lgorithms Sorting

More information

CS420/520 Algorithm Analysis Spring 2009 Lecture 14

CS420/520 Algorithm Analysis Spring 2009 Lecture 14 CS420/520 Algorithm Analysis Spring 2009 Lecture 14 "A Computational Analysis of Alternative Algorithms for Labeling Techniques for Finding Shortest Path Trees", Dial, Glover, Karney, and Klingman, Networks

More information

CS/COE

CS/COE CS/COE 1501 www.cs.pitt.edu/~lipschultz/cs1501/ Weighted Graphs Last time, we said spatial layouts of graphs were irrelevant We define graphs as sets of nodes and edges However, we ll certainly want to

More information

Agenda. Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp

Agenda. Graph Representation DFS BFS Dijkstra A* Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp Graph Charles Lin genda Graph Representation FS BFS ijkstra * Search Bellman-Ford Floyd-Warshall Iterative? Non-iterative? MST Flow Edmond-Karp Graph Representation djacency Matrix bool way[100][100];

More information

Shortest Paths and Minimum Spanning Trees

Shortest Paths and Minimum Spanning Trees /9/ hortest Paths and Minimum panning Trees dmin avid Kauchak cs0 pring 0 ijkstra s algorithm What about ijkstra s on? 0-0 /9/ What about ijkstra s on? ijkstra s algorithm only works for positive edge

More information

TIE Graph algorithms

TIE Graph algorithms TIE-20106 1 1 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common

More information

Chapter 9. Greedy Algorithms: Spanning Trees and Minimum Spanning Trees

Chapter 9. Greedy Algorithms: Spanning Trees and Minimum Spanning Trees msc20 Intro to lgorithms hapter. Greedy lgorithms: Spanning Trees and Minimum Spanning Trees The concept is relevant to connected undirected graphs. Problem: Here is a diagram of a prison for political

More information

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

Single-Source Shortest Paths. CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Single-Source Shortest Paths CSE Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Terminology A network is a directed graph. We will use both terms interchangeably. The

More information

Shortest Paths and Minimum Spanning Trees

Shortest Paths and Minimum Spanning Trees // hortest Paths and Minimum panning Trees avid Kauchak cs pring dmin an resubmit homeworks - for up to half credit back l ue by the end of the week Read book // // // // // Is ijkstra s algorithm correct?

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

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

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS 2 Graphs: Example A directed graph V5 V = { V = E = { E Path: 3 Graphs: Definitions A directed graph V5 V6 A graph G = (V,E) consists of a set of vertices V and a set of edges

More information

Introduction to Algorithms. Minimum Spanning Tree. Chapter 23: Minimum Spanning Trees

Introduction to Algorithms. Minimum Spanning Tree. Chapter 23: Minimum Spanning Trees Introdction to lgorithms oncrete example Imagine: Yo wish to connect all the compters in an office bilding sing the least amont of cable - ach vertex in a graph G represents a compter - ach edge represents

More information

Luke. Leia 2. Han Leia

Luke. Leia 2. Han Leia Reading SE : ata Structures raph lgorithms raph Search hapter.,.,. Lecture raph T raphs are a formalism for representing relationships between objects a graph is represented as = (V, E) Han V is a set

More information

Shortest Paths. CSE 373 Data Structures Lecture 21

Shortest Paths. CSE 373 Data Structures Lecture 21 Shortest Paths CSE 7 Data Structures Lecture Readings and References Reading Section 9., Section 0.. Some slides based on: CSE 6 by S. Wolfman, 000 //0 Shortest Paths - Lecture Path A path is a list of

More information

CS2210 Data Structures and Algorithms

CS2210 Data Structures and Algorithms S1 ata Structures and Algorithms Lecture 1 : Shortest Paths A 4 1 5 5 3 4 Goodrich, Tamassia Outline Weighted Graphs Shortest Paths Algorithm (ijkstra s) Weighted Graphs ach edge has an associated numerical

More information

Minimum Spanning Trees

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

More information

WAN Technology and Routing

WAN Technology and Routing PS 60 - Network Programming WN Technology and Routing Michele Weigle epartment of omputer Science lemson University mweigle@cs.clemson.edu March, 00 http://www.cs.clemson.edu/~mweigle/courses/cpsc60 WN

More information

Weighted Graphs ( 12.5) Shortest Paths. Shortest Paths ( 12.6) Shortest Path Properties PVD ORD SFO LGA HNL LAX DFW MIA PVD PVD ORD ORD SFO SFO LGA

Weighted Graphs ( 12.5) Shortest Paths. Shortest Paths ( 12.6) Shortest Path Properties PVD ORD SFO LGA HNL LAX DFW MIA PVD PVD ORD ORD SFO SFO LGA Shortest Paths A Weighted Graphs (.) In a weighted graph, each edge has an associated numerical value, called the weight of the edge dge weights may represent, distances, costs, etc. xample: In a flight

More information

Introduction: (Edge-)Weighted Graph

Introduction: (Edge-)Weighted Graph Introduction: (Edge-)Weighted Graph c 8 7 a b 7 i d 9 e 8 h 6 f 0 g These are computers and costs of direct connections. What is a cheapest way to network them? / 8 (Edge-)Weighted Graph Many useful graphs

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

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW

CHAPTER 14 GRAPH ALGORITHMS ORD SFO LAX DFW SO OR HPTR 1 GRPH LGORITHMS LX W KNOWLGMNT: THS SLIS R PT ROM SLIS PROVI WITH T STRUTURS N LGORITHMS IN JV, GOORIH, TMSSI N GOLWSSR (WILY 16) 6 OS MINIMUM SPNNING TRS SO 16 PV OR 1 1 16 61 JK 1 1 11 WI

More information

Lecture #10: RELAX(u, v, w) if d[v] >d[u]+w(u, v) then d[v] d[u]+w(u, v) π[v] u

Lecture #10: RELAX(u, v, w) if d[v] >d[u]+w(u, v) then d[v] d[u]+w(u, v) π[v] u Lecture #:.. raph lgorithms: hortest Path (hapter ) Problem iven a directed graph =[V,], and weight function w : R mapping edges to real valued weights. The weight of a path p = hv o,v,..., v k i is the

More information

CS1800: Graph Algorithms (2nd Part) Professor Kevin Gold

CS1800: Graph Algorithms (2nd Part) Professor Kevin Gold S1800: raph lgorithms (2nd Part) Professor Kevin old Summary So ar readth-irst Search (S) and epth-irst Search (S) are two efficient algorithms for finding paths on graphs. S also finds the shortest path.

More information

Note. Out of town Thursday afternoon. Willing to meet before 1pm, me if you want to meet then so I know to be in my office

Note. Out of town Thursday afternoon. Willing to meet before 1pm,  me if you want to meet then so I know to be in my office raphs and Trees Note Out of town Thursday afternoon Willing to meet before pm, email me if you want to meet then so I know to be in my office few extra remarks about recursion If you can write it recursively

More information

CSE 332: Data Structures & Parallelism Lecture 22: Minimum Spanning Trees. Ruth Anderson Winter 2018

CSE 332: Data Structures & Parallelism Lecture 22: Minimum Spanning Trees. Ruth Anderson Winter 2018 SE 33: Data Structures & Parallelism Lecture : Minimum Spanning Trees Ruth nderson Winter 08 Minimum Spanning Trees iven an undirected graph =(V,E), find a graph =(V, E ) such that: E is a subset of E

More information

TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis

TCOM 501: Networking Theory & Fundamentals. Lecture 11 April 16, 2003 Prof. Yannis A. Korilis TOM 50: Networking Theory & undamentals Lecture pril 6, 2003 Prof. Yannis. Korilis 2 Topics Routing in ata Network Graph Representation of a Network Undirected Graphs Spanning Trees and Minimum Weight

More information

Single Source, Shortest Path Problem

Single Source, Shortest Path Problem Lecture : From ijkstra to Prim Today s Topics: ijkstra s Shortest Path lgorithm epth First Search Spanning Trees Minimum Spanning Trees Prim s lgorithm overed in hapter 9 in the textbook Some slides based

More information

Programming Abstractions

Programming Abstractions Programming bstractions S 1 0 6 X ynthia ee Upcoming Topics raphs! 1. asics What are they? ow do we represent them? 2. Theorems What are some things we can prove about graphs? 3. readth-first search on

More information

Module 5 Graph Algorithms

Module 5 Graph Algorithms Module 5 Graph lgorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu 5. Graph Traversal lgorithms Depth First

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

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker Dijkstra s Single Source Shortest Path Algorithm Andreas Klappenecker Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node s in V a weight function w: E -> R. Problem:!!

More information

Shortest Path Algorithms

Shortest Path Algorithms Shortest Path Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node s in V a weight function w: E

More information

CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018

CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018 1 CMPSC 250 Analysis of Algorithms Spring 2018 Dr. Aravind Mohan Shortest Paths April 16, 2018 Shortest Paths The discussion in these notes captures the essence of Dijkstra s algorithm discussed in textbook

More information

1/19/2010. Usually for static, deterministic environment

1/19/2010. Usually for static, deterministic environment To download the discussion slides, go to http://april.eecs.umich.edu/courses/eecs492_w10/wiki/index.php/iscussion_lides eterministic, tochastic and trategic nvironment eterministic ompletely predictable

More information

Minimum Spanning Trees My T. UF

Minimum Spanning Trees My T. UF Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication

More information

Routing. Effect of Routing in Flow Control. Relevant Graph Terms. Effect of Routing Path on Flow Control. Effect of Routing Path on Flow Control

Routing. Effect of Routing in Flow Control. Relevant Graph Terms. Effect of Routing Path on Flow Control. Effect of Routing Path on Flow Control Routing Third Topic of the course Read chapter of the text Read chapter of the reference Main functions of routing system Selection of routes between the origin/source-destination pairs nsure that the

More information

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity. 1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:

More information

Lecture 14: Shortest Paths Steven Skiena

Lecture 14: Shortest Paths Steven Skiena Lecture 14: Shortest Paths Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Suppose we are given

More information

ECE 158A: Lecture 5. Fall 2015

ECE 158A: Lecture 5. Fall 2015 8: Lecture Fall 0 Routing ()! Location-ased ddressing Recall from Lecture that routers maintain routing tables to forward packets based on their IP addresses To allow scalability, IP addresses are assigned

More information

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms Elementary Graph Algorithms: Summary CmSc250 Intro to Algorithms Definition: A graph is a collection (nonempty set) of vertices and edges A path from vertex x to vertex y : a list of vertices in which

More information

Section 7: Dijkstra s

Section 7: Dijkstra s Section 7: ijkstra s Slides by lex Mariakakis with material Kellen onohue, avid Mailhot, and an rossman Late days Things to iscuss o cse33-lateday@cs.washington.edu o 3 assignments left o an use late days

More information

Discussion 8: Link State Routing. CSE 123: Computer Networks Marti Motoyama & Chris Kanich

Discussion 8: Link State Routing. CSE 123: Computer Networks Marti Motoyama & Chris Kanich iscussion 8: Link State Routing S : omputer Networks Marti Motoyama & hris Kanich Schedule Project Questions: mail hris, post to moodle, or attend his OH Homework Questions? Link State iscussion S iscussion

More information

ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE! 1. Link state flooding topology information finding the shortest paths (Dijkstra)

ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE! 1. Link state flooding topology information finding the shortest paths (Dijkstra) ontents ÉOL POLYTHNIQU ÉÉRL LUSNN! 1. Link state flooding topology information finding the shortest paths (ijkstra)! 2. Hierarchical routing with areas! 3. OSP Link State Routing database modelling neighbor

More information

CS350: Data Structures Dijkstra s Shortest Path Alg.

CS350: Data Structures Dijkstra s Shortest Path Alg. Dijkstra s Shortest Path Alg. James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Shortest Path Algorithms Several different shortest path algorithms exist

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

Campus Tour. 1/18/2005 4:08 AM Campus Tour 1

Campus Tour. 1/18/2005 4:08 AM Campus Tour 1 ampus Tour //00 :0 M ampus Tour Outline and Reading Overview of the assignment Review djacency matrix structure (..) Kruskal s MST algorithm (..) Partition T and implementation (..) The decorator pattern

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

TIE Graph algorithms

TIE Graph algorithms TIE-20106 239 11 Graph algorithms This chapter discusses the data structure that is a collection of points (called nodes or vertices) and connections between them (called edges or arcs) a graph. The common

More information

A region is each individual area or separate piece of the plane that is divided up by the network.

A region is each individual area or separate piece of the plane that is divided up by the network. Math 135 Networks and graphs Key terms Vertex (Vertices) ach point of a graph dge n edge is a segment that connects two vertices. Region region is each individual area or separate piece of the plane that

More information

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University

Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University Data Structure Lecture#24: Graphs 2 (Chapter 11) U Kang Seoul National University U Kang 1 In This Lecture Shortest path problem Main idea of Dijkstra s algorithm Cost analysis of Dijkstra s algorithm

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

Campus Tour Goodrich, Tamassia. Campus Tour 1

Campus Tour Goodrich, Tamassia. Campus Tour 1 ampus Tour 00 oodrich, Tamassia ampus Tour raph ssignment oals Learn and implement the adjacency matrix structure an Kruskal s minimum spanning tree algorithm Understand and use the decorator pattern and

More information

Introduction. Example

Introduction. Example OMS0 Introduction Priority queues and ijkstra s algorithm In this lecture we will discuss ijkstra s algorithm, a more efficient way of solving the single-source shortest path problem. epartment of omputer

More information

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

( ). Which of ( ) ( )  #& ( )  # g( n) ( )  # f ( n) Test 1 CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.

More information

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs). Lecture 13 Graph Algorithms I 13.1 Overview This is the first of several lectures on graph algorithms. We will see how simple algorithms like depth-first-search can be used in clever ways (for a problem

More information

Exam 1 Solutions. Jonathan Turner 10/4/01 9/27/01. CS 541 Algorithms and Programs. Be neat and concise, but complete.

Exam 1 Solutions. Jonathan Turner 10/4/01 9/27/01. CS 541 Algorithms and Programs. Be neat and concise, but complete. CS 541 Algorithms and rograms Exam 1 Solutions Jonathan Turner 10/4/01 9/27/01 Be neat and concise, but complete. 1. (15 points) State the general greedy method for finding minimum spanning trees. Show

More information

A Parallel Algorithm for the Single-Source Shortest Path Problem

A Parallel Algorithm for the Single-Source Shortest Path Problem A Parallel Algorithm for the Single-Source Shortest Path Problem Kevin Kelley, Tao Schardl May 12, 2010 Outline The Problem Dijkstra s Algorithm Gabow s Scaling Algorithm Optimizing Gabow Parallelizing

More information

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1 Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm ADS: lects 14 & 15 slide 1 Weighted Graphs Definition 1 A weighted (directed or undirected graph) is a pair (G, W ) consisting

More information

) $ f ( n) " %( g( n)

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

IP Forwarding Computer Networking. Routes from Node A. Graph Model. Lecture 10: Intra-Domain Routing

IP Forwarding Computer Networking. Routes from Node A. Graph Model. Lecture 10: Intra-Domain Routing IP orwarding - omputer Networking Lecture : Intra-omain Routing RIP (Routing Information Protocol) & OSP (Open Shortest Path irst) The Story So ar IP addresses are structure to reflect Internet structure

More information

Sample Solutions to Homework #4

Sample Solutions to Homework #4 National Taiwan University Handout #25 Department of Electrical Engineering January 02, 207 Algorithms, Fall 206 TA: Zhi-Wen Lin and Yen-Chun Liu Sample Solutions to Homework #4. (0) (a) Both of the answers

More information

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131 Graphs Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - Faner 3131 1 Outline Introduction to Graphs Graph Traversals Finding a

More information

Outline. Graphs. Divide and Conquer.

Outline. Graphs. Divide and Conquer. GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.

More information

Data Organization: Creating Order Out Of Chaos

Data Organization: Creating Order Out Of Chaos ata Organization: reating Order Out Of haos 3 Non-linear data structures 5-5 Principles of omputation, arnegie Mellon University - ORTIN Trees tree is a hierarchical (usually non-linear) data structure.

More information

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

( ) ( ) C.  1 n. ( ) $ f n. ( ) B.  log( n! ) ( ) and that you already know ( ) ( )  % g( n) ( )  #& CSE 0 Name Test Summer 008 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time for the following code is in which set? for (i=0; i

More information

Week 9 Student Responsibilities. Mat Example: Minimal Spanning Tree. 3.3 Spanning Trees. Prim s Minimal Spanning Tree.

Week 9 Student Responsibilities. Mat Example: Minimal Spanning Tree. 3.3 Spanning Trees. Prim s Minimal Spanning Tree. Week 9 Student Responsibilities Reading: hapter 3.3 3. (Tucker),..5 (Rosen) Mat 3770 Spring 01 Homework Due date Tucker Rosen 3/1 3..3 3/1 DS & S Worksheets 3/6 3.3.,.5 3/8 Heapify worksheet ttendance

More information

Shortest Paths. Shortest Path. Applications. CSE 680 Prof. Roger Crawfis. Given a weighted directed graph, one common problem is finding the shortest

Shortest Paths. Shortest Path. Applications. CSE 680 Prof. Roger Crawfis. Given a weighted directed graph, one common problem is finding the shortest Shortest Path Introduction to Algorithms Shortest Paths CS 60 Prof. Roger Crawfis Given a weighted directed graph, one common problem is finding the shortest path between two given vertices Recall that

More information

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College Laura Toma Algorithms (csci2200), Bowdoin College Topics Weighted graphs each edge (u, v) has a weight denoted w(u, v) or w uv stored in the adjacency list or adjacency matrix The weight of a path p =

More information

All Shortest Paths. Questions from exercises and exams

All Shortest Paths. Questions from exercises and exams All Shortest Paths Questions from exercises and exams The Problem: G = (V, E, w) is a weighted directed graph. We want to find the shortest path between any pair of vertices in G. Example: find the distance

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018 CS Section # Shortest Paths and MSTs //08 Shortest Paths There are types of shortest paths problems: Single source single destination Single source to all destinations All pairs shortest path In today

More information

Graph ADT. Lecture18: Graph II. Adjacency Matrix. Representation of Graphs. Data Vertices and edges. Methods

Graph ADT. Lecture18: Graph II. Adjacency Matrix. Representation of Graphs. Data Vertices and edges. Methods Graph T S33: ata Structures (0) Lecture8: Graph II ohyung Han S, POSTH bhhan@postech.ac.kr ata Vertices and edges endvertices(e): an array of the two endvertices of e opposite(v,e): the vertex opposite

More information

TCP/IP Networking. Part 3: Forwarding and Routing

TCP/IP Networking. Part 3: Forwarding and Routing TP/IP Networking Part 3: Forwarding and Routing Routing of IP Packets There are two parts to routing IP packets:. How to pass a packet from an input interface to the output interface of a router ( IP forwarding

More information

Lecture 11: Analysis of Algorithms (CS ) 1

Lecture 11: Analysis of Algorithms (CS ) 1 Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest

More information

Parallel Graph Algorithms

Parallel Graph Algorithms Parallel Graph Algorithms Design and Analysis of Parallel Algorithms 5DV050 Spring 202 Part I Introduction Overview Graphsdenitions, properties, representation Minimal spanning tree Prim's algorithm Shortest

More information

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions: Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need

More information

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20. Title Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis Nesrine Damak Fakultät für Informatik TU München 20. September 2010 Nesrine Damak: Classical Shortest-Path Algorithms 1/ 35

More information

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f CS6: Algorithm Design and Analysis Recitation Section 8 Stanford University Week of 5 March, 08 Problem 8-. (Graph Representation) (a) Discuss the advantages and disadvantages of using an adjacency matrix

More information

Breadth-First Search L 1 L Goodrich, Tamassia, Goldwasser Breadth-First Search 1

Breadth-First Search L 1 L Goodrich, Tamassia, Goldwasser Breadth-First Search 1 readth-irst Search 2013 Goodrich, Tamassia, Goldwasser readth-irst Search 1 readth-irst Search readth-first search (S) is a general technique for traversing a graph S traversal of a graph G Visits all

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 13 Graph algorithms Graph representation Minimum spanning trees Greedy algorithms Optimal substructure Greedy choice Prim s greedy MST algorithm Prof.

More information

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati

MA 252: Data Structures and Algorithms Lecture 36. Partha Sarathi Mandal. Dept. of Mathematics, IIT Guwahati MA 252: Data Structures and Algorithms Lecture 36 http://www.iitg.ernet.in/psm/indexing_ma252/y12/index.html Partha Sarathi Mandal Dept. of Mathematics, IIT Guwahati The All-Pairs Shortest Paths Problem

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 3 Data Structures Graphs Traversals Strongly connected components Sofya Raskhodnikova L3.1 Measuring Running Time Focus on scalability: parameterize the running time

More information