The scenario: have an army of ants (or whatever) all starting at the START vertex (say, A), moving at unit speed away from it in all directions. Whenever.

Slides:



Advertisements
Similar presentations
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Advertisements

Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs. Overview What is a graph? Some terminology Types of graph Implementing graphs (briefly) Some graph algorithms Graphs 2/18.
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Priority Queue Sorting (§ 8.1.4) We can use a priority queue to sort a set.
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
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.
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the “shortest path” is the path that.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Search Related Algorithms. Graph Code Adjacency List Representation:
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
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.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
CS 367 Introduction to Data Structures Lecture 8.
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Graph Search Applications, Minimum Spanning Tree
Leftist Trees Linked binary tree.
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
CS 106B Homework 7: Trailblazer
Lecture 12 Graph Algorithms
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
Programming Abstractions
CSC 172 DATA STRUCTURES.
Lecture 6 Shortest Path Problem.
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Outline This topic covers Prim’s algorithm:
Slide Courtesy: Uwash, UT
COMP171 Depth-First Search.
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Minimum Spanning Tree.
Weighted Graphs & Shortest Paths
Slide Courtesy: Uwash, UT
Graph Algorithms: Shortest Path
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
Prim’s algorithm for minimum spanning trees
Chapter 9: Graphs Shortest Paths
Chapter 9: Graphs Spanning Trees
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Heaps Section 6.4, Pg. 309 (Section 9.1).
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

The scenario: have an army of ants (or whatever) all starting at the START vertex (say, A), moving at unit speed away from it in all directions. Whenever a group of ants hits a vertex, they split apart going in all directions. Clearly, the first ant to hit a node has gone along the shortest path. Some things to notice about these ants: 1. If an ant gets to a vertex that's already been visited, it can quit since it can't possibly be the first to anywhere. (this will map to the "if V is visited..." line below) 2. In fact, there's no reason to even start down a path to a vertex if you know it's been visited before. (this will map to the "if X is visited..." line below) Say we wanted to implement this idea in a computer program. What would we need to keep track of? In terms of the vertices, we could keep track of: unseen[X] = false if X has already been visited by the ants val[X] = the time the ants first got there (the length of the shortest path to X) dad[X] = where those ants came from. Then we also need to keep track of the ants: for each group of ants currently active we want to know where they are (what edge are they on) and when are they going to get to the endpoint they're heading towards. Then, in each step of the algorithm, we just need to find out what the next event is ("event" == ants hitting a vertex) and update our data structures.

init: update (start, start, 0) into Pqueue set all val[k] = 0 and unseen[k] = true While queue not empty: (U, V, priority) = pqueue.removeMin(); if V already visited, continue; // corresponds to (1) above mark V as visited (seen). set dad[V] = U. set val[V] = priority for each unvisted (unseen) neighbor X of V: update (V, X, weight(VX edge)) into pqueue. Priority-First Search Minimal Spanning Tree

init: update (start, start, 0) into Pqueue set all val[k] = 0 and unseen[k] = true While queue not empty: (U, V, priority) = pqueue.removeMin(); if V already visited, continue; // corresponds to (1) above mark V as visited (seen). set dad[V] = U. set val[V] = priority for each unvisted (unseen) neighbor X of V: update (V, X, val[V] + weight(VX edge)) into pqueue. Priority-First Search Shortest Path

How long does the above algorithm take? Answer: there are at most |E| "inserts" (because once you send ants down an edge, you will never send them down that edge again) and so also at most |E| removeMins. So, the time is O(|E|*(time for insert) + |E|*(time for removeMin)) Max number of items in pqueue at any point in time is |E|. So, if we can get the inserts and removeMins to O(log n) time we will have time = O(|E| * log(|E|)) We can do this by using a min-heap. To removemin we take the root off (that's the minimum) and then re-make the heap by replacing it with the rightmost leaf and doing a "downheap"/"siftUp" procedure.