CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

Size: px
Start display at page:

Download "CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s"

Transcription

1 CSE 101 Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 6: BFS and Dijkstra s

2 BREADTH FIRST SEARCH (BFS) Given a graph G and a starting vertex s, BFS computes distances from s to every other node. It keeps this information in an array dist. To do this, BFS computes distances layer by layer. It sets dist(s)=0 and the next layer is all the vertices adjacent to s. If v is adjacent to s then it sets dist(v)=1. Once it has assigned distance values 0,1,2, d. The nodes at distance d+1 are the undiscovered nodes adjacent to the d nodes.

3 STACK VERSUS QUEUE The main difference between DFS and BFS is that DFS uses a stack and BFS uses a queue. The queue gives us some extra information. The queue starts with just the node s, the only one that has distance 0. Then for each subsequent distance, there is a point when the queue contains all the nodes at distance d and nothing else. As these nodes are ejected, their undiscovered neighbors are the next nodes injected into the end of the queue.

4 BFS procedure BFS(G, s) Input: Graph G = (V,E), (directed or undirected) and a vertex s in V. Output: For all vertices u reachable from s, dist(u) is the distance from s to u. and for all vertices u not reachable from s, dist(u) = for each vertex u in V: dist(u)= dist(s) = 0 Q = [s] (queue just containing s) while Q is not empty u = eject(q) for all edges (u,v) in E if dist(v)= then inject(q,v) dist(v)=dist(u) + 1

5 EJECT (DEQUEUE) u = eject(q) sets u equal to the first entry of Q and then removes that value from Q. Example: If Q = [B,D,A] then u = eject(q) means that now u has the value B and Q = [D,A]

6 INJECT (ENQUEUE) inject(q,v) puts v at the end of the list Q. Example: if Q = [B,A,D] then inject(q,f) means that now Q = [B,A,D,F]

7 EXAMPLE C A F B E D

8 CORRECTNESS OF BFS We want to show that BFS assigns dist() correctly to all vertices reachable from s. Proof by induction on distance. Base Case: dist(s) = 0. Inductive hypothesis: For any vertex v that is distance k from s, dist(v) = k. Inductive step: Suppose u is distance k + 1 (WTS: BFS assigns dist(u) = k + 1.)

9 CORRECTNESS OF BFS (PROOF CONT.) Inductive Step: Suppose u is distance k + 1 from s. dist(u) starts at infinity There exists a vertex w such that w is distance k from s and ( w,u) is in E. In the last for loop when w is ejected, we encounter the edge ( w,u) and dist(u) is infinity so we inject u into Q and set dist(u) = dist(w) + 1 = k + 1.

10 RUNTIME Each vertex is initially set to infinity. Then each vertex reachable by s is put into Q and taken out of Q so there are V initializations and at most 2 V queue operations. In the while loop, it eventually visits all edges reachable from s (once in directed graphs and twice in undirected graphs.) so there are at most E, (2 E ) times it visits an edge. So, worst case it takes 3 V + 2 E = O V + E operations. procedure BFS(G,s) for each vertex u in V: distance(u)=i nfinity dist(s) = 0 Q = [s] (queue just containing s) while Q is not empty u = eject(q) for all edges (u,v) in E if dist(v)=infi nity then inject(q,v) dist(v)=dist(u) + 1

11 SHORTEST PATH TREE Is there a way to output the dist values and the shortest path tree? procedure BFS(G,s) for each vertex u in V: dist(u)=infini ty prev(u)=nil dist(s) = 0 Q = [s] (queue just containing s) while Q is not empty u = eject(q) for all edges (u,v) in E if dist(v)=infi nity then inject(q,v) dist(v)=dis t(u) + 1 prev(v)=u

12 BFS A B C D E H F I G J K L M

13 DFS VS BFS DFS gives info about the whole graph BFS gives info related to a given vertex within the graph BFS uses a queue DFS uses a stack BFS does not restart at other connected components since all vertices not connected to your starting vertex are distance infinity away.

14 GRAPHS WITH EDGE LENGTHS

15 EDGE LENGTHS (WEIGHTS) edges can be given values such as distance cost time we will denote the length (weight) of edge e = (u, v) as l e, l (u,v), l e, l(u, v)

16 BFS ON WEIGHTED GRAPHS. BFS only works to find shortest distances on graphs in which each edge has equal weight. A 3 B 2 C 1 1 D 4 E F

17 BFS ON WEIGHTED GRAPHS. On a graph G with integer edge lengths, form G by adding l e 1 many new vertices between u and v for every edge e = (u, v). Then run BFS on G. A 3 B 2 C A B C 1 1 D 4 E F D E F G G

18 A 0 1 B 2 C D E F EXAMPLE

19 PROBLEMS WITH THIS METHOD If the edge lengths (weights) are large integers then it is impractical. In this example with 10 vertices, we must add 1,783 more vertices!!!!!!!!

20 ALARM CLOCK. ORD To find the shortest path to every vertex starting from SAN, we set an alarm clock for each edge coming out of SAN. So, we set the alarm for DEN for 100 seconds and ORD for 250 seconds. We let time pass and wait for the next alarm to go off. The first alarm to go off is DEN. So we look at all outgoing edges from DEN. If the time it takes to get to a vertex is faster through DEN, then we replace the alarm. In this case, there are still 150 seconds remaining but there is an edge that is 100 seconds away so we reset the edge to ORD to be 200. SAN DEN

21 ALARM CLOCK ALGORITHM Set alarm clock for vertex s at time 0 If next alarm goes off at time T for a vertex u then distance(u) = T for each edge (u,v) in E if no alarm is set for v then set it for T + l(u,v) if there is an alarm for v that is later than T + l(u,v) then reset the alarm for the earlier time if there is an alarm for v that is earlier than T + l(u,v) then leave the alarm as it is.

22 HOW TO IMPLEMENT This alarm clock algorithm works great. There is a problem. How do we implement it and teach a computer to do it. (We must learn how to quickly add vertices and take them out of a structure depending on their alarm setting.) The structure type we want to use is called a priority queue.

23 PRIORITY QUEUE A priority queue is a data structure of a set of objects (vertices) along with key values for each object that can be changed (alarm settings.) And it can support the following operations. insert(h,u) deletemin(h) decreasekey(h,u) makequeue(s)

24 DIJKSTRA S SHORTEST PATH ALGORITHM procedure dijkstra(g,l,s) Input: a graph G = (V,E) (directed or undirected.) a set of edge lengths l = {l(e):e is in E} s is the starting vertex Output: for all vertices u reachable from s, dist(u) is set to the distance from s to u and for all vertices unreachable dist(u) is set to infinity.

25 DIJKSTRA S SHORTEST PATH ALGORITHM procedure dijkstra(g,l,s) for all u in V dist(u) := infinity prev(u) := nil dist(s) := 0 H := makequeue(v) while H is not empty u := deletemin(h) for all edges (u,v) in E if dist(v) > dist(u) + l(u,v) then dist(v):= dist(u) + l(u,v) prev(v):=u decreasekey(h,v)

26 DIJKSTRA S SHORTEST PATH ALGORITHM The dist() value refers to the current alarm setting. A value of infinity means that an alarm has not been set yet. The prev(u) is set to the vertex before u in the current shortest path to u from s. By following these prev values, we can reconstruct the shortest paths. Dijkstra s algorithm is the same as BFS but it uses a priority queue instead of a regular queue.

27 ORD DIJKSTRA EXAMPLE IAD DEN SAN DFW ATL

28 RUNTIME OF DIJKSTRA S procedure dijkstra(g,l,s) for all u in V dist(u) := infinity prev(u) := nil dist(s) := 0 H := makequeue(v) while H is not empty u := deletemin(h) for all edges (u,v) in E if dist(v) > dist(u) + l(u,v) then dist(v):= dist(u) + l(u,v) prev(v):=u decreasekey(h,v) makequeue(v) deletemin(h) decreasekey(h,v)

29 RUNTIME OF DIJKSTRA S procedure dijkstra(g,l,s) for all u in V dist(u) := infinity prev(u) := nil dist(s) := 0 H := makequeue(v) while H is not empty u := deletemin(h) for all edges (u,v) in E if dist(v) > dist(u) + l(u,v) then dist(v):= dist(u) + l(u,v) prev(v):=u decreasekey(h,v) deletemin V decreasekey E

30 ARRAY AS A PRIORITY QUEUE Array: an ordered list of vertices each with a key value. [key(a),key(b),key(c),key(d),key(e),key(f)] makequeue: deletemin: decreasekey:

31 ARRAY AS A PRIORITY QUEUE Dijkstra s takes time makequeue + deletemin V + decreasekey E If we use an array then it will take V + O V V + O 1 E = O V 2 + E = O V 2

32 BINARY HEAP F 6 D 8 A 10 A complete binary tree of objects (vertices) with the property that each key value of an object is less than the key value of its parent. B 10 H 8 E 12 K 12 J 11 C 12 L 15 Q 14 N 14 G 22 O 26 I 16 P 26 M [F 6, D 8, A 10, B 10, H 8, E 12, K 12, J 11, C 12, L 15, Q 14, N 14, G 22, O 26, I 16, P 26, M 13 ]

33 BINARY HEAP [F 6, D 8, A 10, B 10, H 8, E 12, K 12, J 11, C 12, L 15, Q 14, N 14, G 22, O 26, I 16, P 26, M 13 ] The Binary heap can be implemented with an array a[n] of vertices. The children of a i are a 2i and a 2i+1. The parent of a i is a i/2.

34 BINARY HEAP (DELETEMIN) F 6 D 8 A 10 The object with the minimum key value is guaranteed to be the root. Once you take it out, you must reorder the tree. You replace the root with the last object and let it trickle down. J 11 P 26 M 13 B 10 H 8 E 12 K 12 C 12 L 9 Q 14 N 14 G 22 O 26 I 16 [F 6, D 8, A 10, B 10, H 8, E 12, K 12, J 21, C 12, L 9, Q 14, N 14, G 22, O 26, I 16, P 26, M 13 ] M 13

35 M 13 BINARY HEAP (DELETEMIN) F 6 D 8 A 10 The object with the minimum key value is guaranteed to be the root. Once you take it out, you must reorder the tree. You replace the root with the last object and let it trickle down. J 11 B 10 H 8 E 12 K 12 C 12 L 15 Q 14 N 14 G 22 O 26 I 16 P [F M 136, D 8, A 10, B 10, H 8, E 12, K 12, J 21, C 12, L 9, Q 14, N 14, G 22, O 26, I 16, P 26 ]

36 BINARY HEAP (DELETEMIN) D 8 F 6 The object with the minimum key value is guaranteed to be the root. Once you take it out, you must reorder the tree. You replace the root with the last object and let it trickle down. J 11 B 10 A M H 8 E 12 K 12 C 12 L 15 Q 14 N 14 G 22 O 26 I 16 P [D 8, MD 138, A 10, B 10, H 8, E 12, K 12, J 21, C 12, L 9, Q 14, N 14, G 22, O 26, I 16, P 26 ]

37 BINARY HEAP (DELETEMIN) D 8 F 6 The object with the minimum key value is guaranteed to be the root. Once you take it out, you must reorder the tree. You replace the root with the last object and let it trickle down. J 11 H 8 A 10 B 10 M 13 E 12 K 12 C 12 L 15 Q 14 N 14 G 22 O 26 I 16 P [D 8, H 8, A 10, B 10, MH 138, E 12, K 12, J 21, C 12, L 9, Q 14, N 14, G 22, O 26, I 16, P 26 ]

38 BINARY HEAP (DELETEMIN) When the last object is put in as the root, it may trickle down the entire length of the heap, the time taken is O(log n ) where n is the number of objects in the heap. When performing Dijkstra s algorithm, the number of objects in the heap is V so the time taken is O(log V ).

39 BINARY HEAP (DECREASEKEY) F 6 D 8 A 10 When you decrease a key, you may have to adjust the heap by having the decreased key object bubble up. B 10 H 8 E 12 K 12 J 11 C 12 L 15 Q 14 N 14 G 22 O 26 I 16 P 26 M [F 6, D 8, A 10, B 10, H 8, E 12, K 12, J 11, C 12, L 15, Q 14, N 14, G 22, O 26, I 16, P 26, M 13 ]

40 BINARY HEAP (DECREASEKEY) F 6 D 8 A 10 When you decrease a key, you may have to adjust the heap by having the decreased key object bubble up. B 10 H 8 E 12 K 12 J 11 C 12 L 15 Q 14 N 14 G 22 O 8 I 16 P 26 M [F 6, D 8, A 10, B 10, H 8, E 12, K 12, J 11, C 12, L 15, Q 14, N 14, G 22, O 26 8, I 16, P 26, M 13 ]

41 BINARY HEAP (DECREASEKEY) F 6 D 8 A 10 When you decrease a key, you may have to adjust the heap by having the decreased key object bubble up. B 10 H 8 E 12 O 8 J 11 C 12 L 15 Q 14 N 14 G 22 K 12 I 16 P 26 M [F 6, D 8, A 10, B 10, H 8, E 12, KO 12 8, J 11, C 12, L 15, Q 14, N 14, G 22, K 12, I 16, P 26, M 13 ]

42 BINARY HEAP (DECREASEKEY) F 6 D 8 O 8 When you decrease a key, you may have to adjust the heap by having the decreased key object bubble up. B 10 H 8 E 12 A 10 J 11 C 12 L 15 Q 14 N 14 G 22 K 12 I 16 P 26 M [F 6, D 8, AO 10 8, B 10, H 8, E 12, A 10, J 11, C 12, L 15, Q 14, N 14, G 22, K 12, I 16, P 26, M 13 ]

43 BINARY HEAP (DECREASEKEY) When the object decreases key, it may bubble up the entire heap, the time taken is O(log n ) where n is the number of objects in the heap. When performing Dijkstra s algorithm, the number of objects in the heap is V so the time taken is O(log V ).

44 BINARY HEAP makequeue: O( V ) deletemin: O(log V ). decreasekey: O(log V ) Dijkstra s takes time makequeue + deletemin V + decreasekey E If we use an array then it will take O( V ) + O log( V ) V + O log( V ) E = O( V + E )log( V ) )

45 ARRAY VS BINARY HEAP Array O( V 2 ) Binary Heap O( V + E )log( V ) ) Sparse graphs: E = O( V ) Dense graphs: E = O( V 2 )

46 DIJKSTRA S ALGORITHM WITH DIFFERENT PRIORITY QUEUES. Runtime of Array: O V 2 Runtime of Binary heap: O V + E log V Fibonacci Heap!!!: O V log V + E

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 5: SCC/BFS DECOMPOSITION There is a linear time algorithm that decomposes a directed graph into its

More information

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5

Dijkstra s Algorithm and Priority Queue Implementations. CSE 101: Design and Analysis of Algorithms Lecture 5 Dijkstra s Algorithm and Priority Queue Implementations CSE 101: Design and Analysis of Algorithms Lecture 5 CSE 101: Design and analysis of algorithms Dijkstra s algorithm and priority queue implementations

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:

More information

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University Algorithms (VII) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Depth-first search in undirected graphs Exploring graphs explore(g, v) Input: G = (V, E) is a graph; v V Output:

More information

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 8: Negative Edges DIJKSTRA S ALGORITHM WITH DIFFERENT PRIORITY QUEUES. Runtime of Array: O V 2 Runtime

More information

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University Algorithms (V) Path in Graphs Guoqiang Li School of Software, Shanghai Jiao Tong University Review of the Previous Lecture Exploring Graphs EXPLORE(G, v) input : G = (V, E) is a graph; v V output: visited(u)

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 6: BFS, SPs, Dijkstra Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Distance in a Graph The distance between two nodes is the length

More information

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2 Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there

More information

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSC 373 Lecture # 3 Instructor: Milad Eftekhar Huffman encoding: Assume a context is available (a document, a signal, etc.). These contexts are formed by some symbols (words in a document, discrete samples from a signal, etc). Each symbols s i is occurred

More information

Algorithms (I) Introduction. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Algorithms (I) Introduction. Guoqiang Li. School of Software, Shanghai Jiao Tong University Algorithms (I) Introduction Guoqiang Li School of Software, Shanghai Jiao Tong University Instructor and Teaching Assistants Guoqiang LI Instructor and Teaching Assistants Guoqiang LI Homepage: http://basics.sjtu.edu.cn/

More information

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, Notes 7 for CS 170

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, Notes 7 for CS 170 UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 7 Lecturer: David Wagner February 13, 003 Notes 7 for CS 170 1 Dijkstra s Algorithm Suppose each edge (v, w) of our graph has a

More information

CSC Intro to Intelligent Robotics, Spring Graphs

CSC Intro to Intelligent Robotics, Spring Graphs CSC 445 - Intro to Intelligent Robotics, Spring 2018 Graphs Graphs Definition: A graph G = (V, E) consists of a nonempty set V of vertices (or nodes) and a set E of edges. Each edge has either one or two

More information

Design and Analysis of Algorithms (I)

Design and Analysis of Algorithms (I) Design and Analysis of Algorithms (I) Introduction Guoqiang Li School of Software, Shanghai Jiao Tong University Instructor and Teaching Assistants Guoqiang LI Instructor and Teaching Assistants Guoqiang

More information

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

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

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

Graph Representations and Traversal

Graph Representations and Traversal COMPSCI 330: Design and Analysis of Algorithms 02/08/2017-02/20/2017 Graph Representations and Traversal Lecturer: Debmalya Panigrahi Scribe: Tianqi Song, Fred Zhang, Tianyu Wang 1 Overview This lecture

More information

Content. 1 Algorithms. 2 Assignment and Knapsack problem 3 Bin Packing. 4 Scheduling

Content. 1 Algorithms. 2 Assignment and Knapsack problem 3 Bin Packing. 4 Scheduling Content 1 Algorithms 2 Assignment and Knapsack problem 3 Bin Packing 4 Scheduling 5 Graph algorithms 5.1 Definitions 5.2 Depth First Search (DFS) and Breadth First Search (BFS) 5.3 Topological Sorting

More information

Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search

Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search 6.082 Fall 2006 Shortest Path Routing, Slide 1 Routing in an

More information

Solution. violating the triangle inequality. - Initialize U = {s} - Add vertex v to U whenever DIST[v] decreases.

Solution. violating the triangle inequality. - Initialize U = {s} - Add vertex v to U whenever DIST[v] decreases. Solution Maintain a set U of all those vertices that might have an outgoing edge violating the triangle inequality. - Initialize U = {s} - Add vertex v to U whenever DIST[v] decreases. 1. Check if the

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 4 Graphs Definitions Traversals Adam Smith 9/8/10 Exercise How can you simulate an array with two unbounded stacks and a small amount of memory? (Hint: think of a

More information

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

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

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

(Re)Introduction to Graphs and Some Algorithms

(Re)Introduction to Graphs and Some Algorithms (Re)Introduction to Graphs and Some Algorithms Graph Terminology (I) A graph is defined by a set of vertices V and a set of edges E. The edge set must work over the defined vertices in the vertex set.

More information

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)

More information

Dr. Alexander Souza. Winter term 11/12

Dr. Alexander Souza. Winter term 11/12 Algorithms Theory 11 Shortest t Paths Dr. Alexander Souza 1. Shortest-paths problem Directed graph G = (V, E) Cost function c : E R 1 2 1 3 3 2 4 4 2 6 6 5 3 2 Distance between two vertices Cost of a path

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

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

(Refer Slide Time: 00:18)

(Refer Slide Time: 00:18) Programming, Data Structures and Algorithms Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 11 Lecture 58 Problem: single source shortest

More information

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices

More information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016 CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,

More information

Algorithms (VI) Greedy Algorithms. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Algorithms (VI) Greedy Algorithms. Guoqiang Li. School of Software, Shanghai Jiao Tong University Algorithms (VI) Greedy Algorithms Guoqiang Li School of Software, Shanghai Jiao Tong University Review of the Previous Lecture Lengths on Edges BFS treats all edges as having the same length. It is rarely

More information

Priority Queues. Meld(Q 1,Q 2 ) merge two sets

Priority Queues. Meld(Q 1,Q 2 ) merge two sets Priority Queues MakeQueue Insert(Q,k,p) Delete(Q,k) DeleteMin(Q) Meld(Q 1,Q 2 ) Empty(Q) Size(Q) FindMin(Q) create new empty queue insert key k with priority p delete key k (given a pointer) delete key

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 5 Exploring graphs Adam Smith 9/5/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Puzzles Suppose an undirected graph G is connected.

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

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

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

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

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V) Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from

More information

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100 Minimum Spanning Trees Prim s and Kruskal CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:

More information

1 The Shortest Path Problem

1 The Shortest Path Problem CS161 Lecture 11 Single Source Shortest Paths Scribed by: Romil Verma (2015), Virginia Date: May 8, 2016 1 The Shortest Path Problem In this lecture, we ll discuss the shortest path problem. Assume we

More information

CS Final - Review material

CS Final - Review material CS4800 Algorithms and Data Professor Fell Fall 2009 October 28, 2009 Old stuff CS 4800 - Final - Review material Big-O notation Though you won t be quizzed directly on Big-O notation, you should be able

More information

Algorithms for Data Science

Algorithms for Data Science Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Shortest paths in weighted graphs (Bellman-Ford, Floyd-Warshall) Outline 1 Shortest paths in graphs with

More information

Unit #9: Graphs. CPSC 221: Algorithms and Data Structures. Will Evans 2012W1

Unit #9: Graphs. CPSC 221: Algorithms and Data Structures. Will Evans 2012W1 Unit #9: Graphs CPSC 1: Algorithms and Data Structures Will Evans 01W1 Unit Outline Topological Sort: Getting to Know Graphs with a Sort Graph ADT and Graph Representations Graph Terminology More Graph

More information

1 Dijkstra s Algorithm

1 Dijkstra s Algorithm Lecture 11 Dijkstra s Algorithm Scribes: Himanshu Bhandoh (2015), Virginia Williams, and Date: November 1, 2017 Anthony Kim (2016), G. Valiant (2017), M. Wootters (2017) (Adapted from Virginia Williams

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations

More information

Algorithms for Data Science

Algorithms for Data Science Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Thursday, October 1, 2015 Outline 1 Recap 2 Shortest paths in graphs with non-negative edge weights (Dijkstra

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

CSE 373: Data Structures and Algorithms

CSE 373: Data Structures and Algorithms CSE 373: Data Structures and Algorithms Lecture 6: Dijkstra s Algorithm (Graphs) Instructor: Lilian de Greef Quarter: Summer 207 Today Announcements Graph Traversals Continued Remarks on DFS & BFS Shortest

More information

Unit 2: Algorithmic Graph Theory

Unit 2: Algorithmic Graph Theory Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue

More information

Lecture 28: Graphs: Shortest Paths (Part 1)

Lecture 28: Graphs: Shortest Paths (Part 1) CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 28: Graphs: Shortest Paths (Part 1) 10:00 AM, Apr 6, 2018 Contents 1 Recording Paths Taken 1 2 A Weighty Matter 2 3 Dijkstra s Algorithm

More information

Dijkstra s Shortest Path Algorithm

Dijkstra s Shortest Path Algorithm Dijkstra s Shortest Path Algorithm DPV 4.4, CLRS 24.3 Revised, October 23, 2014 Outline of this Lecture Recalling the BFS solution of the shortest path problem for unweighted (di)graphs. The shortest path

More information

6.1 Minimum Spanning Trees

6.1 Minimum Spanning Trees CS124 Lecture 6 Fall 2018 6.1 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

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

CS4800: Algorithms & Data Jonathan Ullman

CS4800: Algorithms & Data Jonathan Ullman CS4800: Algorithms & Data Jonathan Ullman Lecture 13: Shortest Paths: Dijkstra s Algorithm, Heaps DFS(?) Feb 0, 018 Navigation s 9 15 14 5 6 3 18 30 11 5 0 16 4 6 6 3 19 t Weighted Graphs A graph with

More information

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1 Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms

More information

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review 1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

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 4 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

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. UNIT III TREES A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items. Tree: A tree is a finite set of one or more nodes such that, there

More information

22.1 Representations of graphs

22.1 Representations of graphs 22.1 Representations of graphs There are two standard ways to represent a (directed or undirected) graph G = (V,E), where V is the set of vertices (or nodes) and E is the set of edges (or links). Adjacency

More information

Week 12: Minimum Spanning trees and Shortest Paths

Week 12: Minimum Spanning trees and Shortest Paths Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601

More information

Outlines: Graphs Part-2

Outlines: Graphs Part-2 Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree

More information

DIJKSTRA'S ALGORITHM. By Laksman Veeravagu and Luis Barrera

DIJKSTRA'S ALGORITHM. By Laksman Veeravagu and Luis Barrera DIJKSTRA'S ALGORITHM By Laksman Veeravagu and Luis Barrera THE AUTHOR: EDSGER WYBE DIJKSTRA "Computer Science is no more about computers than astronomy is about telescopes." http://www.cs.utexas.edu/~ewd/

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

More information

UCSD CSE 101 MIDTERM 1, Winter 2008

UCSD CSE 101 MIDTERM 1, Winter 2008 UCSD CSE 101 MIDTERM 1, Winter 2008 Andrew B. Kahng / Evan Ettinger Feb 1, 2008 Name: }{{} Student ID: }{{} Read all of the following information before starting the exam. This test has 3 problems totaling

More information

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 7 MAS 714 Hartmut Klauck Theory of Computing Lecture 7 MAS 714 Hartmut Klauck Shortest paths in weighted graphs We are given a graph G (adjacency list with weights W(u,v)) No edge means W(u,v)=1 We look for shortest paths from

More information

Minimum Spanning Trees Ch 23 Traversing graphs

Minimum Spanning Trees Ch 23 Traversing graphs Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs

More information

The Shortest Path Problem

The Shortest Path Problem The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

More information

COT 6405 Introduction to Theory of Algorithms

COT 6405 Introduction to Theory of Algorithms COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first

More information

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1

Graph Algorithms Introduction to Data Structures. Ananda Gunawardena 7/31/2011 1 Graph Algorithms 15-121 Introduction to Data Structures Ananda Gunawardena 7/31/2011 1 In this lecture.. Main idea is finding the Shortest Path between two points in a Graph We will look at Graphs with

More information

Elementary Graph Algorithms

Elementary Graph Algorithms Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)

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

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

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,

More information

Question Points Score TOTAL 50

Question Points Score TOTAL 50 UCSD CSE 101 Section B00, Winter 2015 MIDTERM February 5, 2015 NAME: Student ID: Question Points Score 1 10 2 10 3 10 4 10 5 10 TOTAL 50 INSTRUCTIONS. Be clear and concise. Write your answers in the space

More information

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G

More information

CSE 100: GRAPH SEARCH

CSE 100: GRAPH SEARCH CSE 100: GRAPH SEARCH Announcements PA3 released Checkpoint due Tuesday, May 5 @10:00pm Final submission due Thursday, May 14 @10:00PM Start early! Start early! Start early! Start early! Start early! I

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Topics: Priority Queue Linked List implementation Sorted Unsorted Heap structure implementation TODAY S TOPICS NOT ON THE MIDTERM 2 Some priority queue

More information

Description of The Algorithm

Description of The Algorithm Description of The Algorithm Dijkstra s algorithm works by solving the sub-problem k, which computes the shortest path from the source to vertices among the k closest vertices to the source. For the dijkstra

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

Minimum Spanning Trees

Minimum Spanning Trees CS124 Lecture 5 Spring 2011 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

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

CS473-Algorithms I. Lecture 14-A. Graph Searching: Breadth-First Search. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-Algorithms I. Lecture 14-A. Graph Searching: Breadth-First Search. Cevdet Aykanat - Bilkent University Computer Engineering Department CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search 1 Graph Searching: Breadth-First Search Graph G =(V, E), directed or undirected with adjacency list repres. GOAL: Systematically explores

More information

CS Algorithms and Complexity

CS Algorithms and Complexity CS 350 - Algorithms and Complexity Graph Theory, Midterm Review Sean Anderson 2/6/18 Portland State University Table of contents 1. Graph Theory 2. Graph Problems 3. Uninformed Exhaustive Search 4. Informed

More information

Classical Shortest-Path Algorithms

Classical Shortest-Path Algorithms DISTANCE PROBLEMS IN NETWORKS - THEORY AND PRACTICE Classical Shortest-Path Algorithms Nesrine Damak October 10, 2010 Abstract In this work, we present four algorithms for the shortest path problem. The

More information

Graph Traversal CSCI Algorithms I. Andrew Rosenberg

Graph Traversal CSCI Algorithms I. Andrew Rosenberg Graph Traversal CSCI 700 - Algorithms I Andrew Rosenberg Last Time Introduced Graphs Today Traversing a Graph A shortest path algorithm Example Graph We will use this graph as an example throughout today

More information

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch] Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Directed Graphs Let V be a finite set and E a binary relation on V, that is, E VxV. Then the pair G=(V,E) is called a directed graph.

More information

Review: Graph Theory and Representation

Review: Graph Theory and Representation Review: Graph Theory and Representation Graph Algorithms Graphs and Theorems about Graphs Graph implementation Graph Algorithms Shortest paths Minimum spanning tree What can graphs model? Cost of wiring

More information

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems

Chapter 24. Shortest path problems. Chapter 24. Shortest path problems. 24. Various shortest path problems. Chapter 24. Shortest path problems Chapter 24. Shortest path problems We are given a directed graph G = (V,E) with each directed edge (u,v) E having a weight, also called a length, w(u,v) that may or may not be negative. A shortest path

More information

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013 CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such

More information

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10 CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices

More information

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees trees CS 220: Discrete Structures and their Applications A tree is an undirected graph that is connected and has no cycles. Trees Chapter 11 in zybooks rooted trees Rooted trees. Given a tree T, choose

More information

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms Chapter 3 CSE 417: Algorithms and Computational Complexity Graphs Reading: 3.1-3.6 Winter 2012 Graphs and Graph Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

More information

Graphs & Digraphs Tuesday, November 06, 2007

Graphs & Digraphs Tuesday, November 06, 2007 Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements

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

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Session 18. April 1, 2009 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3137 Announcements Homework 4 due next class Huffman compression must handle any

More information

Algorithms and Data Structures 2014 Exercises and Solutions Week 9

Algorithms and Data Structures 2014 Exercises and Solutions Week 9 Algorithms and Data Structures 2014 Exercises and Solutions Week 9 November 26, 2014 1 Directed acyclic graphs We are given a sequence (array) of numbers, and we would like to find the longest increasing

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

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo

More information