Another dynamic program... +----------+ %...*..*..*% %..........% %*..*******% %*.*.***.*.% Q: What is the shortest path that delivers papers.

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
CSE 373, Copyright S. Tanimoto, 2001 Graphs Graphs 2 Incidence and Adjacency Representing a graph with an adjacency matrix, an incidence matrix,
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs CS3240, L. grewe.
1 CSE 326: Data Structures: Graphs Lecture 19: Monday, Feb 24, 2003.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Graph & BFS.
Floyd’s Algorithm (shortest-path problem) Section 8.2.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 261 – Data Structures Graphs. Used in a variety of applications and algorithms Graphs represent relationships or connections Superset of trees (i.e.,
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Karsten Steinhaeuser Aaron Wenger December 09, 2003.
COMP171 Depth-First Search.
CSE 780 Algorithms Advanced Algorithms Graph Algorithms Representations BFS.
Algorithms All pairs shortest path
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.
All-Pairs Shortest Paths
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
9 Priority Queues, Heaps, and Graphs. 9-2 What is a Heap? A heap is a binary tree that satisfies these special SHAPE and ORDER properties: –Its shape.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
Search Related Algorithms. Graph Code Adjacency List Representation:
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
Graphs, BFS, DFS and More…
Prime numbers Jordi Cortadella Department of Computer Science.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
ACM today This week's problems… New and improved :-) ACM table slacking! not slacking… missing entries? let me know…
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
All-pairs Shortest Paths. p2. The structure of a shortest path: All subpaths of a shortest path are shortest paths. p : a shortest path from vertex i.
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
ACM reminders October HMC Mock contest 9: :30 November regional contest This is the next ACM meeting !! Contest-like problems dynamic.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
ACM reminders October HMC Mock contest Good times ? November ACM contest November Final acm class & contest wrap-up PendingAzusa Pacific.
Trees, Binary Search Trees, Balanced Trees, Graphs Graph Fundamentals Telerik Algo Academy
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.
All-Pairs Shortest Paths
Fundamental Programming Fundamental Programming More Expressions and Data Types.
Basic Graph Algorithms Programming Puzzles and Competitions CIS 4900 / 5920 Spring 2009.
Contest Algorithms January 2016 Describe shortest path trees, SSSP, APSP, and three algorithms: Dijkstra, Bellman-Ford, Floyd-Warshall 9. Shortest Paths.
Harbin, China 2010 finals ACM today… ! (2009) Knapsack DP for NP! Floyd-Warshall DP for APSP! Max Flow.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
Graphs – Part III CS 367 – Introduction to Data Structures.
Tutorial 8 An optional eighth tutorial will be held the week of March 6. This tutorial will give you practice with and feedback on oral presentation and.
Shortest Path Graph represents highway system Edges have weights
Discussion section #2 HW1 questions?
Search Related Algorithms
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Depth-First Search CSE 2011 Winter April 2019.
Depth-First Search CSE 2011 Winter April 2019.
Graphs.
Dijkstra's Shortest Path Algorithm
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
GRAPH TRAVERSAL.
Presentation transcript:

Another dynamic program %...*..*..*% % % %*..*******% %*.*.***.*.% Q: What is the shortest path that delivers papers to each * ? door stairs Table: tracks the shortest path that delivers all of the papers up to floor N, ending on both the left and the right. Ends left Ends right Floor21345 measured up to the last paper

All-pairs shortest paths... “Floyd-Warshall algorithm” A B E D C A B C D E FROM TO Matrix representation D0D0 ABCDE

All-pairs shortest paths A B C D E D 0 = (d ij ) A B C D E D 1 = (d ij ) 1 d ij = shortest distance from i to j through {1, …, k} k d ij = k In general, A B C D E

All-pairs shortest paths A B C D E D 2 = (d ij ) A B C D E D 3 = (d ij ) A B C D E D 4 = (d ij ) 4 A B C D E D 5 = (d ij ) 5 to store the path, another matrix can track the last intermediate vertex

Floyd-Warshall Pseudocode Input:(the initial edge-cost matrix) Output: (the final path-cost matrix) D 0 = (d ij ) 0 D n = (d ij ) n for k = 1 to n // intermediate vertices considered for i = 1 to n // the “from” vertex for j = 1 to n // the “to” vertex d ij = min{ d ij, d ik + d kj } k-1 k best, ignoring vertex k best, including vertex k

Code quirks for ( i = cols - 2; i >= 0; i++ ) { if ( reachable[i + 1] && !reachable[i] && fits(row, i) ) { reachable[i] = 1; } #include void f(int& i) { i++; } void f(int& i, int& j) { i = j = i += j; } int main() { int i = 10, j = 100; f(( i++, j )); printf("i is %d and j is %d\n",i,j); return 0; }

#include,,,,, string start, finish; // the starting and ending cities map > dests; // children (destinations) of each city void BFS() { map visited; // a list of cities already visited in the BFS queue > q; // the queue of nodes not yet visited pair current(start,0); // an STL pair is used to maintain path length list ::iterator i; // used to run through each city’s children bool failed = false; while (current.first != finish) // current.first == current city checked for goal { string city = current.first; // give current.first a simpler name visited[city] = true; // mark that city as already visited for(i = dests[city].begin(); i != dests[city].end(); i++) // for each child, if (!visited[*i]) // if it’s unvisited, q.push( pair (*i, current.second+1) ); // we put it and its path length // onto q if (q.empty()) { failed = true; break; } current = q.front(); // set up for next loop q.pop(); } if (failed) cout << "Try again next week." << endl; // no way to get thre else cout << current.second << endl; // prints path length } BFS from We ship cheap! message: STL is good!

Things to consider... Saturday: meet at Olin 1265 (or the parking lot north of Olin) at 8:15 AM (a bit earlier to go for breakfast) What to consider bringing We have whiteboards & markers printouts of ACM problems’ code other code you know/want to use C/C++ references algorithm references (CLR, e.g.) configuration files:.emacs,.vimrc,.bashrc,.cshrc,.aliases, etc. anything else you might want to have (Any written material is OK, digital media is not permitted and there is no web access.) Other Info 60 second CPU time limit C++ files must end in.C available commands: compile myfile.C submit # myfile.C question filename answers score, timeleft, getdata compiles a file submits a file for problem number # asks the judges a question (in a file) looks at all answers to questions gets score, time remaining, or data files

Blazing Convex Hull