Chapter 28 Weighted Graphs and Applications

Slides:



Advertisements
Similar presentations
Chapter 25 Lists, Stacks, Queues, and Priority Queues
Advertisements

Chapter 20 Recursion.
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Advanced Piloting Cruise Plot.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 10 second questions
ZMQS ZMQS
Improved Shortest Path Algorithms for Nearly Acyclic Directed Graphs L. Tian and T. Takaoka University of Canterbury New Zealand 2007.
Randomized Algorithms Randomized Algorithms CS648 1.
Chapter 24 Lists, Stacks, and Queues
ABC Technology Project
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
2 |SharePoint Saturday New York City
VOORBLAD.
15. Oktober Oktober Oktober 2012.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Chapter 5 Test Review Sections 5-1 through 5-4.
Addition 1’s to 20.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Copyright © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 15 2 k Factorial Experiments and Fractions.
Intracellular Compartments and Transport
CS203 Lecture 15.
1 Unit 1 Kinematics Chapter 1 Day
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
How Cells Obtain Energy from Food
Immunobiology: The Immune System in Health & Disease Sixth Edition
CpSc 3220 Designing a Database
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 27 Graphs and Applications.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 23 Weighted Graphs and Applications.
1 Chapter 28 Weighted Graph Applications. 2 Objectives F To represent weighted edges using adjacency matrices and priority queues (§28.2). F To model.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 28 Weighted Graph.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 30 Graphs and Applications.
Chapter 28 Weighted Graphs and Applications
Chapter 29 Weighted Graphs and Applications
Presentation transcript:

Chapter 28 Weighted Graphs and Applications

Weighted Graph Animation www.cs.armstrong.edu/liang/animation/ShortestPathAnimation.html

Weighted Graph Animation www.cs.armstrong.edu/liang/animation/WeightedGraphLearningTool.html

Objectives To represent weighted edges using adjacency matrices and priority queues (§28.2). To model weighted graphs using the WeightedGraph class that extends the AbstractGraph class (§28.3). To design and implement the algorithm for finding a minimum spanning tree (§28.4). To define the MST class that extends the Tree class (§28.4). To design and implement the algorithm for finding single-source shortest paths (§28.5). To define the ShortestPathTree class that extends the Tree class (§28.5). To solve the weighted nine tail problem using the shortest path algorithm (§28.6).

Representing Weighted Graphs Representing Weighted Edges: Edge Array Weighted Adjacency Matrices Priority Adjacency Lists

Representing Weighted Edges: Edge Array int[][] edges = {{0, 1, 2}, {0, 3, 8}, {1, 0, 2}, {1, 2, 7}, {1, 3, 3}, {2, 1, 7}, {2, 3, 4}, {2, 4, 5}, {3, 0, 8}, {3, 1, 3}, {3, 2, 4}, {3, 4, 6}, {4, 2, 5}, {4, 3, 6} };

Representing Weighted Edges: Edge Array

Priority Adjacency Lists

TestWeightedGraph TestWeightedGraph Graph AbstractGraph WeightedGraph

Minimum Spanning Trees A graph may have many spanning trees. Suppose that the edges are weighted. A minimum spanning tree is a spanning tree with the minimum total weights. For example, the trees in Figures 28.3(b), 28.3(c), 28.3(d) are spanning trees for the graph in Figure 28.3(a). The trees in Figures 28.3(c) and 28.3(d) are minimum spanning trees.

Minimum Spanning Tree Algorithm Let V denote the set of vertices in the graph; Let T be a set for the vertices in the spanning tree; Initially, add the starting vertex to T; while (size of T < n) { find u in T and v in V – T with the smallest weight on the edge (u, v), as shown in Figure 28.4; add v to T; }

Minimum Spanning Tree Algorithm

Minimum Spanning Tree Algorithm Example

Implementing MST Algorithm

Time Complexity For each vertex, the program constructs a priority queue for its adjacent edges. It takes O(log|V|) time to insert an edge to a priority queue and the same time to remove an edge from the priority queue. So the overall time complexity for the program is O(|E|log|V|) , where |E| denotes the number of edges and |V| denotes the number of vertices.

Test MST TestMinimumSpanningTree TestMinimumSpanningTree

Shortest Path §27.1 introduced the problem of finding the shortest distance between two cities for the graph in Figure 13.1. The answer to this problem is to find a shortest path between two vertices in the graph.

Single Source Shortest Path Algorithm shortestPath(s) { Let V denote the set of vertices in the graph; Let T be a set that contains the vertices whose path to s have been found; Initially T contains source vertex s; while (size of T < n) { find v in V – T with the smallest costs[u] + w(u, v) value among all u in T; add v to T; }

Single Source Shortest Path Algorithm

SP Algorithm Example

SP Algorithm Example

SP Algorithm Example

SP Algorithm Example

SP Algorithm Example

SP Algorithm Example

SP Algorithm Implementation TestShortestPath TestShortestPath

SP Algorithm Example

Shortest Path Animation www.cs.armstrong.edu/liang/animation/ShortestPathAnimation.html

The Weighted Nine Tail Problem The nine tail problem is to find the minimum number of the moves that lead to all coins face down. Each move flips a head coin and its neighbors. The weighted nine tail problem assigns the number of the flips as a weight on each move. For example, you can move from the coins in Figure 28(a) to Figure 28(b) by flipping the three coins. So the weight for this move is 3. WeightedNineTailModel