Computer Science Club It is easier to change the specification to fit the program than vice versa.

Slides:



Advertisements
Similar presentations
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
Advertisements

§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
CSC 2300 Data Structures & Algorithms April 13, 2007 Chapter 9. Graph Algorithms.
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.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
§2 Topological Sort 〖 Example 〗 Courses needed for a computer science degree at a hypothetical university How shall we convert this list into a graph?
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
Semester 10 Time sure flies.. PotW Solution One possible solution is to randomly search the grid: o At each point in your search, look at the (up to four)
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 23, 2009.
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 22, 2010.
CS 261 – Data Structures Graphs. Used in a variety of applications and algorithms Graphs represent relationships or connections Superset of trees (i.e.,
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 10 Recursion. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Explain the underlying concepts of recursion.
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.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Announcements Mailing list: –you should have received messages Office hours onlineonline –start next week.
ASC Program Example Part 3 of Associative Computing Examining the MST code in ASC Primer.
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Course notes CS2606: Data Structures and Object-Oriented Development Graphs Department of Computer Science Virginia Tech Spring 2008 (The following notes.
UNCA CSCI November, 2001 These notes were prepared by the text’s author Clifford A. Shaffer Department of Computer Science Virginia Tech Copyright.
Graphs 2 Kevin Kauffman CS 309s. Problem We have sprinklers in our yard which need to be connected with pipe. Assuming pipes may only intersect at sprinkler.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Dijkstra’s Algorithm. 2 Shortest-path Suppose we want to find the shortest path from node X to node Y It turns out that, in order to do this, we need.
Data Structures Week 9 Towards Weighted BFS So, far we have measured d s (v) in terms of number of edges in the path from s to v. Equivalent to assuming.
Dijkstra’s algorithm N: set of nodes for which shortest path already found Initialization: (Start with source node s) n N = {s}, D s = 0, “s is distance.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
Moooooo Or: How I learned to stop worrying and love USACO.
ALG0183 Algorithms & Data Structures Lecture 21 d Dijkstra´s algorithm 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks Chapter 14 Weiss.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Dijkstra’s Algorithm. This algorithm finds the shortest path from a source vertex to all other vertices in a weighted directed graph without negative.
Binary Search From solving a problem to verifying an answer.
Lecture 5: Developing Procedural Thinking (How to think like a programmer) B Burlingame 30 Sept 2015.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
Recursion When to use it and when not to use it. Basics of Recursion Recursion uses a method Recursion uses a method Within that method a call is made.
Dijkstra's algorithm For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that.
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 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
Contest Algorithms January 2016 Describe shortest path trees, SSSP, APSP, and three algorithms: Dijkstra, Bellman-Ford, Floyd-Warshall 9. Shortest Paths.
E E Module 5 © Wayne D. Grover 2002, (for non-negative edge weights only) Key concepts: “labelling”, “scanning” Label = {distance, predecessor}.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 10.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Zaiben Chen et al. Presented by Lian Liu. You’re traveling from s to t. Which gas station would you choose?
 Given: › Total number of cows (N) › Number of cows allowed to advance (K) › Number of votes each cow receives (A, B)  Rules: › Top K cows (w/ greatest.
TIRGUL 10 Dijkstra’s algorithm Bellman-Ford Algorithm 1.
Graphs – Part III CS 367 – Introduction to Data Structures.
Lynbrook Computer Science “The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the.
Shortest Path from G to C Using Dijkstra’s Algorithm
Single-Source Shortest Paths
Common final examinations
Shortest Path Graph represents highway system Edges have weights
Discussion section #2 HW1 questions?
A* Path Finding Ref: A-star tutorial.
CSE 373: Data Structures and Algorithms
CSE 214 – Computer Science II Graph Walking
Shortest Path Algorithms
Algorithms: Design and Analysis
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Compact routing schemes with improved stretch
Efficiently Estimating Travel Time
Dijkstra's Shortest Path Algorithm
Presentation transcript:

Computer Science Club It is easier to change the specification to fit the program than vice versa.

Last Week’s Problem Denise’s fabulousness Set of items, each with a weight and fabulousness Max fabulousness restricted to a certain weight

Solution public class Item { private int weight; private int fabulousness; public Item( int weight, int fabulousness ) { this.weight = weight; this.fabulousness = fabulousness; } public int getWeight() { return weight; } public int getFabulousness() { return fabulousness; } }

Solution (cont.) Variables: static int[][] fabKnapsackMemo = new int[1000][9012];

Solution (cont.) public static int fabulousKnapsackCorrect( Item[] items, int itemNum, int maxWeight ) { // check bounds if( itemNum = items.length ) return 0; // haven't already calculated this value if( fabKnapsackMemo[itemNum][maxWeight] == 0 ) { Item item = items[itemNum]; int itemWeight = item.getWeight(); int itemValue = item.getFabulousness();

Solution (cont.) // 0 items or 0 weight will both result in a // max fabulousness of 0 fabKnapsackMemo[0][maxWeight] = 0; fabKnapsackMemo[itemNum][0] = 0; // can't add this item because it's too heavy if( itemWeight > maxWeight ) // just as good as best fabulousness with one less item fabKnapsackMemo[itemNum][maxWeight] = fabulousKnapsackCorrect( items, itemNum - 1, maxWeight );

Solution (cont.) else fabKnapsackMemo[itemNum][maxWeight] = Math.max( // best fabulousness with one less item fabulousKnapsackCorrect( items, itemNum - 1, maxWeight ), // maximum fabulousness of enough weight to accommodate this item plus the fabulousness of it fabulousKnapsackCorrect( items, itemNum - 1, maxWeight - itemWeight ) + itemValue ); } // max fabulousness return fabKnapsackMemo[itemNum][maxWeight]; }

USACO Today is the last day to take the contest If you want to try it out or practice, take bronze – Bronze doesn’t count for anything Everybody should at least try silver/gold Read the problem and directions – Read the tips for Java on the contest page – The timer starts when you click the problems – Read the input conditions – Read how they want you to process input/output

USACO (cont.) ~3 hours (2 for qualification rounds) ~3-4 problems (2 for qualification rounds) Header: /* ID: youridhere LANG: C/C++/JAVA PROG: progname */ Scan: “progname.in” and write: “progname.out” Good luck!

Problem of the Week Cancelled due to USACO Algorithm presentation instead

Dijkstra’s Algorithm Used to find the shortest path between a starting position and destination. Given a graph with specified distances of the directional paths between nodes: Task: Find the shortest path from Node a (initial node) to Node f (destination). For example, A-C-D-F has a distance of = 15. The path A-C-E-F has a distance of = 11. Is there a path even SHORTER than that? Can you be sure your path is the shortest possible?

3 2 Dijkstra’s (cont.) The Steps Step 1: Each node has a distance value. (a = 0, others = ∞) Step 2: Two node sets: visited and unvisited (init: none visited) Step 3: a = curNode Step 4: (recursive step!) - Update unvisited neighbors of curNode with new shortest dist - move curNode to visited set - new curNode = smallest unvisited node

3 2 Dijkstra’s (cont.) Finishing Up When curNode = destination, shortest path = value of final node. Try to trace the algorithm and find the shortest path and minimal distance. Consider… Why don’t we need to re-check visited nodes? Why can’t there be a shorter path to a visited node?

Wrap Up No membership dues Remember to sign in Take USACO Thanks for coming