Algorithms Detour - Shortest Path

Slides:



Advertisements
Similar presentations
Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Advertisements

Problem solving with graph search
O(N 1.5 ) divide-and-conquer technique for Minimum Spanning Tree problem Step 1: Divide the graph into  N sub-graph by clustering. Step 2: Solve each.
Discrete Math for Computer Science. Mathematical Model Real-world Problem Computerized Solution Abstract Model Transformed Model picture of the real worldpicture.
7.3 Kruskal’s Algorithm. Kruskal’s Algorithm was developed by JOSEPH KRUSKAL.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 7 Network Flow Models.
The Shortest Path Problem
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Programming & Data Structures
COSC 2007 Data Structures II Chapter 14 Graphs III.
CPSC 320: Intermediate Algorithm Design & Analysis Greedy Algorithms and Graphs Steve Wolfman 1.
L3-Network Algorithms L3 – Network Algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems by: Irene Rangel, updated Nov by Abdulghani.
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.
UNIT 2 LESSON 6 CS PRINCIPLES. UNIT 2 LESSON 6 OBJECTIVES Students will be able to: Write an algorithm for solving the minimum spanning tree (MST) problem.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Graphs 1 Neil Ghani University of Strathclyde. Where are we …. We studied lists: * Searching and sorting a list Then we studied trees: * Efficient search.
Encryption with Keys and Passwords
Greedy Algorithms.
Programming Abstractions
Functions and Top-Down Design
School of Computing Clemson University Fall, 2012
What Are Routers? Routers are an intermediate system at the network layer that is used to connect networks together based on a common network layer protocol.
EECS 203 Lecture 20 More Graphs.
Looping and Random Numbers
Chapter 2: Business Efficiency Lesson Plan
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Chapter 2: Business Efficiency Lesson Plan
Programming Abstractions
Minimum Spanning Tree.
Visualizing Prim’s MST Algorithm Used to Trace the Algorithm in Class
Graphs & Graph Algorithms 2
Graph Theory.
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
Shortest Paths.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
Decision Maths Dijkstra’s Algorithm.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Section 14.4 Trees.
Lecture 6 Shortest Path Problem.
Chapter 2: Business Efficiency Business Efficiency
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
Shortest-Paths Trees Kun-Mao Chao (趙坤茂)
CSE 373: Data Structures and Algorithms
Heuristic Algorithms via VBA
Lecture 24 CSE 331 Oct 25, 2013.
OVERVIEW OF NETWORKS AND GRAPHS
Advanced Analysis of Algorithms
Warm Up – Friday.
Lecture 23 CSE 331 Oct 24, 2011.
Hannah Tang and Brian Tjaden Summer Quarter 2002
Louisiana Travels.
Graph Searching.
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Networks Kruskal’s Algorithm
CSE 373: Data Structures and Algorithms
Graph Theory I In today’s lesson we will look at:
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Weighted Graphs & Shortest Paths
Heuristic Algorithms via VBA
Heuristic Algorithms via VBA
CSE 373 Data Structures and Algorithms
and 6.855J Dijkstra’s Algorithm
Graphs.
Shortest Paths.
Prim’s algorithm for minimum spanning trees
Approximation Algorithms
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
7 The Mathematics of Networks
Presentation transcript:

Algorithms Detour - Shortest Path Lesson 2-7 AP Computer Science Principles

Objectives Students will be able to: Reason about a general solution (algorithm) for a problem while examining specific instances of it. Follow a pseudocode algorithm for the single source shortest path problem. Informally analyze an algorithm to state how “long” it takes to run relative to the size of the problem.

Minimal Spanning Tree vs. Shortest Path Last time you developed an algorithm for the Minimum Spanning Tree (MST) problem. The MST is useful for knowing the most cost- effective way to build or connect a network together. But today we’re going to look at a different problem -- the “Shortest Path Problem” -- which is also a widely studied problem in computer science.

Shortest Path Problem Given a graph of nodes and edges, where the weights of the edges represent some cost (distance, time, money, etc.), find the lowest-cost path between any two nodes.

Shortest Path Problem Typically, we think of the shortest path problem like a map with roads between towns or different points in a big city and we’re trying to find the shortest/fastest way to get from one place to another. This is what map apps that give you driving directions do. But the shortest path problem doesn’t have to represent traveling anywhere at all.  You could use a graph of a social network to figure out how closely connected you are to some other person, for example, how many friend connections separate me from the president of the United States?

Shortest Path Wroksheet Look at the first chart. What is the shortest path from A→C? Just because A is connected to C doesn’t mean that is the shortest path!

Shortest Path Worksheet Look at the most direct path: A→C has a cost of 7 Look at other connections A→B→C has a cost of 5 Consider other options A→B→D→C has a cost of 6 A→B→D→E→C has a cost of 6

Your turn… Find the shortest path from A→C on each of the remaining charts. ...but you should be thinking... Remember: in computer science, “solving a problem” doesn’t mean finding an answer to an instance of a problem; it means finding an algorithm that might be able to solve any instance of that problem. As you look at the graphs on the next page, your brain is working to find a solution. You might think you’re just trying “random stuff” but you’re not. You are using your human intelligence to help you. Think about your own thinking process. Could you express what you are thinking to solve this problem as an algorithm?

Your turn… Now that you have the shortest path from A→C, go back to each chart and find the shortest paths from: A→B A→D A→E

What’s Your Algorithm? What algorithm did you use to find the shortest paths? What makes the algorithm harder/easier than minimum spanning tree?

Shorest Path and Routers The reason we have routers is because we want to send messages from our router to lots and lots of different locations. So a more interesting problem on the Internet is finding not just the path from my router to one other router, but the path from my router to EVERY other router! This is known as the Single Source Shortest Path Problem (SSSP). Today we’re going to look at and analyze a famous algorithm that solves this problem.

Dijkstra’s Shortest Path Algorithm You team will be given the algorithm and a graph. Together you will act as the computer, interpreting the instructions and trying to trace out the algorithm and follow its steps. Part of analyzing an algorithm is trying it out on many different inputs. So, each group will have a different node to start with on the graph and we will test the algorithm to see if it works and then see what we think about it, in terms of its correctness and efficiency.

Compare Your Results Find your corresponding group Graph A with Graph E Graph B with Graph F Graph C with Graph H Graph D with Graph G

Compare Your Results As a group: Compare the shortest path diagrams; these form a tree extending from the source node. Are the shortest path trees from two different sources the same? What about the path between the two source nodes? If so, why? If not, why not? Based on your experience, would this algorithm find the shortest path for any graph of nodes and edges? Is there a way to stop early? That is, is there a way to stop processing the algorithm because you know you’ve found the shortest path tree? Can you guarantee that you could always stop early? Why or why not?

Stage 7 Complete Stage 7