10/2/2015 3:00 PMCampus Tour1. 10/2/2015 3:00 PMCampus Tour2 Outline and Reading Overview of the assignment Review Adjacency matrix structure (§12.2.3)

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
Advertisements

Chapter 9 Greedy Technique. Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible - b feasible.
Lecture 15. Graph Algorithms
© 2004 Goodrich, Tamassia Campus Tour1. © 2004 Goodrich, Tamassia Campus Tour2 Graph Assignment Goals Learn and implement the adjacency matrix structure.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
Spring 2007Shortest Paths1 Minimum Spanning Trees JFK BOS MIA ORD LAX DFW SFO BWI PVD
© 2004 Goodrich, Tamassia Breadth-First Search1 CB A E D L0L0 L1L1 F L2L2.
Breadth-First Search1 Part-H3 Breadth-First Search CB A E D L0L0 L1L1 F L2L2.
1 Graphs ORD DFW SFO LAX Many slides taken from Goodrich, Tamassia 2004.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 Minimum Spanning Trees (§ 13.7) Spanning subgraph Subgraph of a graph G containing all the vertices of.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
CSC311: Data Structures 1 Chapter 13: Graphs II Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
© 2004 Goodrich, Tamassia Shortest Paths1 C B A E D F
CSC 213 Lecture 24: Minimum Spanning Trees. Announcements Final exam is: Thurs. 5/11 from 8:30-10:30AM in Old Main 205.
Minimum Spanning Trees
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Shortest Paths C B A E D F
Graphs Part 2. Shortest Paths C B A E D F
Graphs – ADTs and Implementations ORD DFW SFO LAX
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
Graphs. Data Structure for Graphs. Graph Traversals. Directed Graphs. Shortest Paths. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013.
Spring 2007Graphs1 ORD DFW SFO LAX
GRAPHS 1. Outline 2  Undirected Graphs and Directed Graphs  Depth-First Search  Breadth-First Search.
© 2010 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
Minimum Spanning Tree: Prim’s & Kruskal’s Algorithms Presenter: Michal Karpinski.
1 Weighted Graphs CSC401 – Analysis of Algorithms Lecture Notes 16 Weighted Graphs Objectives: Introduce weighted graphs Present shortest path problems,
Data Structures and Algorithms1 Data Structures and algorithms (IS ZC361) Weighted Graphs – Shortest path algorithms – MST S.P.Vimal BITS-Pilani
Minimum- Spanning Trees
Graphs Upon completion you will be able to:
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
© 2010 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
1 COMP9024: Data Structures and Algorithms Week Twelve: Graphs (II) Hui Wu Session 1, 2014
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
Graphs 10/24/2017 6:47 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Shortest Paths C B A E D F Shortest Paths
14 Graph Algorithms Hongfei Yan June 8, 2016.
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Shortest Paths C B A E D F Shortest Paths 1
Minimum Spanning Trees
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Minimum Spanning Tree 11/3/ :04 AM Minimum Spanning Tree
Graphs.
Graphs.
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Campus Tour 11/16/2018 3:14 PM Campus Tour Campus Tour
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Minimum Spanning Trees
Minimum Spanning Trees
Chapter 13 Graph Algorithms
Graphs ORD SFO LAX DFW Graphs Graphs
Minimum Spanning Tree Algorithms
Campus Tour 2/23/ :26 AM Campus Tour Campus Tour
Breadth-First Search L0 L1 L2 C B A E D F 4/25/2019 3:12 AM
Minimum Spanning Trees
Minimum Spanning Trees (MSTs)
Breadth-First Search L0 L1 L2 C B A E D F 5/14/ :22 AM
Breadth-First Search L0 L1 L2 C B A E D F 7/28/2019 1:03 PM
Presentation transcript:

10/2/2015 3:00 PMCampus Tour1

10/2/2015 3:00 PMCampus Tour2 Outline and Reading Overview of the assignment Review Adjacency matrix structure (§12.2.3) Kruskal’s MST algorithm (§12.7.1) Partition ADT and implementatio The decorator pattern (§12.3.1) The traveling salesperson problem Definition Approximation algorithm

10/2/2015 3:00 PMCampus Tour3 Graph Assignment Goals Learn and implement the adjacency matrix structure an Kruskal’s minimum spanning tree algorithm Understand and use the decorator pattern Your task Implement the adjacency matrix structure for representing a graph Implement Kruskal’s MST algorithm Frontend Computation and visualization of an approximate traveling salesperson tour

10/2/2015 3:00 PMCampus Tour4 Adjacency Matrix Structure Edge list structure Augmented vertex objects Integer key (index) associated with vertex 2D-array adjacency array Reference to edge object for adjacent vertices Null for non nonadjacent vertices u v w ab  1  2  a uv w 01 2 b

10/2/2015 3:00 PMCampus Tour5 Kruskal’s Algorithm The vertices are partitioned into clouds We start with one cloud per vertex Clouds are merged during the execution of the algorithm Partition ADT: makeSet(o) : create set {o} and return a locator for object o find(l) : return the set of the object with locator l union(A,B) : merge sets A and B Algorithm KruskalMSF(G) Input weighted graph G Output labeling of the edges of a minimum spanning forest of G Q  new heap-based priority queue for all v  G.vertices() do l  makeSet(v) { elementary cloud } setLocator(v,l) for all e  G.edges() do Q.insert(weight(e), e) while  Q.isEmpty() e  Q.removeMin() [u,v]  G.endVertices(e) A  find(getLocator(u)) B  find(getLocator(v)) if A  B setMSFedge(e) { merge clouds } union(A, B)

10/2/2015 3:00 PMCampus Tour6 Example B G C A F D E H 11 9 B G C A F D E H 11 9 B G C A F D E H 11 9 B G C A F D E H 11 9

10/2/2015 3:00 PMCampus Tour7 Example (contd.) four steps two steps B G C A F D E H 11 9 B G C A F D E H 11 9 B G C A F D E H 11 9 B G C A F D E H 11 9

10/2/2015 3:00 PMCampus Tour8 Partition Implementation Partition implementation A set is represented the sequence of its elements A position stores a reference back to the sequence itself (for operation find ) The position of an element in the sequence serves as locator for the element in the set In operation union, we move the elements of the smaller sequence into to the larger sequence Worst-case running times makeSet, find : O(1) union : O(min(n A, n B )) Amortized analysis Consider a series of k Partiton ADT operations that includes n makeSet operations Each time we move an element into a new sequence, the size of its set at least doubles An element is moved at most log 2 n times Moving an element takes O(1) time The total time for the series of operations is O(k  n log n)

10/2/2015 3:00 PMCampus Tour9 Analysis of Kruskal’s Algorithm Graph operations Methods vertices and edges are called once Method endVertices is called m times Priority queue operations We perform m insert operations and m removeMin operations Partition operations We perform n makeSet operations, 2m find operations and no more than n  1 union operations Label operations We set vertex labels n times and get them 2m times Kruskal’s algorithm runs in time O((n  m) log n) time provided the graph has no parallel edges and is represented by the adjacency list structure

10/2/2015 3:00 PMCampus Tour10 Decorator Pattern Labels are commonly used in graph algorithms Auxiliary data Output Examples DFS: unexplored/visited label for vertices and unexplored/ forward/back labels for edges Dijkstra and Prim-Jarnik: distance, locator, and parent labels for vertices Kruskal: locator label for vertices and MSF label for edges The decorator pattern extends the methods of the Position ADT to support the handling of attributes (labels) has(a) : tests whether the position has attribute a get(a) : returns the value of attribute a set(a, x) : sets to x the value of attribute a destroy(a) : removes attribute a and its associated value (for cleanup purposes) The decorator pattern can be implemented by storing a dictionary of (attribute, value) items at each position

10/2/2015 3:00 PMCampus Tour11 Traveling Salesperson Problem A tour of a graph is a spanning cycle (e.g., a cycle that goes through all the vertices) A traveling salesperson tour of a weighted graph is a tour that is simple (i.e., no repeated vertices or edges) and has has minimum weight No polynomial-time algorithms are known for computing traveling salesperson tours The traveling salesperson problem (TSP) is a major open problem in computer science Find a polynomial-time algorithm computing a traveling salesperson tour or prove that none exists B D C A F E Example of traveling salesperson tour (with weight 17)

10/2/2015 3:00 PMCampus Tour12 TSP Approximation We can approximate a TSP tour with a tour of at most twice the weight for the case of Euclidean graphs Vertices are points in the plane Every pair of vertices is connected by an edge The weight of an edge is the length of the segment joining the points Approximation algorithm Compute a minimum spanning tree Form an Eulerian circuit around the MST Transform the circuit into a tour