unweighted path lengths

Slides:



Advertisements
Similar presentations
Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Advertisements

CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Breadth-First and Depth-First Search
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
CMSC 341 Graphs 2. 2 Weighted Shortest Path Problem Single-source shortest-path problem: Given as input a weighted graph, G = (V,E), and a distinguished.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Tort Law: Negligence Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
1 Graph theory Outline A graph is an abstract data type for storing adjacency relations –We start with definitions: Vertices, edges, degree and sub-graphs.
1 A* search Outline In this topic, we will look at the A* search algorithm: –It solves the single-source shortest path problem –Restricted to physical.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Single-source shortest path Shortest Path Given a weighted directed graph, one common problem is finding the shortest path between two given vertices.
Graphs – Breadth First Search
Outline This topic covers merge sort
The mechanics of recursion
A vertex u is reachable from vertex v iff there is a path from v to u.
Stack.
Topological Sort In this topic, we will discuss: Motivations
Outline The bucket sort makes assumptions about the data being sorted
Csc 2720 Instructor: Zhuojun Duan
Outline This topic discusses the insertion sort We will discuss:
Unweighted Shortest Path Neil Tang 3/11/2010
CSC 172 DATA STRUCTURES.
CSE 421: Introduction to Algorithms
Graphs Representation, BFS, DFS
Poisson distribution.
Open addressing.
Node-based storage with arrays
All-pairs Shortest Path
All-pairs shortest path
Lecture 13 CSE 331 Oct 1, 2012.
Elementary Graph Algorithms
Outline This topic covers Prim’s algorithm:
Chapter 11 Graphs.
Graphs Part 2 Adjacency Matrix
Shortest Path Algorithms
Richard Anderson Autumn 2016 Lecture 5
Lecture 12 CSE 331 Sep 26, 2011.
Lecture 11 CSE 331 Sep 21, 2017.
Lecture 12 CSE 331 Sep 22, 2014.
Graph Implementation.
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
A vertex u is reachable from vertex v iff there is a path from v to u.
CMSC 341 Graphs 2.
Recursive functions.
Sorted arrays.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

unweighted path lengths Single source unweighted path lengths

Outline This topic looks at another problem solved by breadth-first traversals Finding all path lengths in an unweighted graph

Determining Distances Problem: find the distance from one vertex v to all other vertices Use a breadth-first traversal Vertices are added in layers The starting vertex is defined to be in the zeroeth layer, L0 While the kth layer is not empty: All unvisited vertices adjacent to verticies in Lk are added to the (k + 1)st layer Any unvisited vertices are said to be an infinite distance from v Reference: Kleinberg and Tardos

Determining Distances Consider this graph: find the distance from A to each other vertex

Determining Distances A forms the zeroeth layer, L0 A

Determining Distances The unvisited vertices B, F and G are adjacent to A These form the first layer, L1 B F G

Determining Distances We now begin popping L1 vertices: pop B H is adjacent to B It is tagged L2 F G H

Determining Distances Popping F pushes E onto the queue It is also tagged L2 G H E

Determining Distances We pop G which has no other unvisited neighbours G is the last L1 vertex; thus H and E form the second layer, L2 H E

Determining Distances Popping H in L2 adds C and I to the third layer L3 E C I

Determining Distances E has no more adjacent unvisited vertices Thus C and I form the third layer, L3 C I

Determining Distances The unvisited vertex D is adjacent to vertices in L3 This vertex forms the fourth layer, L4

Determining Distances Theorem: If, in a breadth-first traversal of a graph, two vertices v and w appear in layers Li and Lj, respectively and {v, w} is an edge in the graph, then i and j differ by at most one Proof: If i = j, we are done If i ≠ j, without loss of generality, assume i < j Because v ∈ Li, w does not appear in any previous layer, and {v, w} is an edge in the graph, it follows that w ∈ Li + 1 Thus, j = i + 1 Therefore, i and j differ by at most one Reference: Kleinberg and Tardos

Sumary This topic found the unweighted path length from a single vertex to all other vertices A breadth-first traversal was used The first vertex is marked as layer 0 Vertices added to the queue by one in layer k are marked as layer k + 1 Later, we will see different algorithms for finding the shortest path length in weighted graphs

References Wikipedia, http://en.wikipedia.org/wiki/Shortest_path http://en.wikipedia.org/wiki/Breadth-first_search [1] Jon Kleinberg and Éva Tardos, Algorithm Design, Addison Wesley, 2006, §§3.2-5, pp.78-99. These slides are provided for the ECE 250 Algorithms and Data Structures course. The material in it reflects Douglas W. Harder’s best judgment in light of the information available to him at the time of preparation. Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. Douglas W. Harder accepts no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.