1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 25: Graph Traversal, DAGs, and Weighted Graphs.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Part A - Terminology and Traversals
Analysis of Algorithms Depth First Search. Graph A representation of set of objects Pairs of objects are connected Interconnected objects are called “vertices.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Algorithms and Data Structures
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Chapter 8, Part I Graph Algorithms.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
1 Spanning Trees Lecture 20 CS2110 – Spring
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Graph Traversals CSC 172 SPRING 2002 LECTURE 26. Traversing graphs Depth-First Search like a post-order traversal of a tree Breath-First Search Less like.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Graph Traversals CSC 172 SPRING 2004 LECTURE 21. Announcements  Project 3 is graded  handed back Tuesday  Grad spam, tonight – if you are really anxious.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Minimum Spanning Trees
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Depth-First Search Lecture 21: Graph Traversals
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Graphs and Paths : Chapter 15 Saurav Karmakar
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
CSC 213 – Large Scale Programming Lecture 31: Graph Traversals.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Review Graph Directed Graph Undirected Graph Sub-Graph Spanning Sub-Graph Degree of a Vertex Weighted Graph Elementary and Simple Path Link List Representation.
Graph Search Applications, Minimum Spanning Tree
CSC 172 DATA STRUCTURES.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Minimum Spanning Tree Chapter 13.6.
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Short paths and spanning trees
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
CSE373: Data Structures & Algorithms Lecture 19: Spanning Trees
Depth-First Search Graph Traversals Depth-First Search DFS.
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Minimum Spanning Tree.
Chapter 16 1 – Graphs Graph Categories Strong Components
Minimum spanning trees
Minimum Spanning Trees (MSTs)
Prim’s algorithm for minimum spanning trees
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 25: Graph Traversal, DAGs, and Weighted Graphs

2 Graph Traversal

3 Slide adapted from Goodrich & Tamassia

4 Exploring a Labyrinth Without Getting Lost A depth-first search in an undirected graph G is like wandering in a labyrinth with a string and a can of red paint without getting lost. –Start at vertex s –Tie the string to s –Paint s red (visited) –Set u to be s (the current vertex) –Travel on an arbitrary edge (u,v), trailing string behind –If v is already visited, follow the string back to u –Else if v is unvisited, paint v red –Set u (current vertex) to v and repeat –Keep visiting and unrolling (backtracking) until we finally arrive back at s

5 Slide adapted from Goodrich & Tamassia DFS Starting at vertex A Discovery edges solid Back edges dashed Unvisited nodes black a)Initial graph b)Path of edges from A until node linking back to A found c)Start from B, reach F, a dead end (because E and I have already been visited) d)After backtracking to C, going on to G and hitting J, another dead end.

6 Slide adapted from Goodrich & Tamassia e)After backtracking to G f)After backtracking to N (which had been sitting on the stack waiting)

7 Slide adapted from Goodrich & Tamassia

8

9

10 Slide adapted from Goodrich & Tamassia

11 Slide adapted from Goodrich & Tamassia

12 Slide adapted from Goodrich & Tamassia

13 Slide adapted from Goodrich & Tamassia

14 Digraphs (Directed Graphs)

15 Slide adapted from Goodrich & Tamassia (Directed Graphs)

16 Slide adapted from Goodrich & Tamassia

17 Slide adapted from Goodrich & Tamassia

18 DAGs Directed Acyclic Graphs

19 Slide adapted from Goodrich & Tamassia

20 Slide adapted from Goodrich & Tamassia

21 Slide adapted from Goodrich & Tamassia

22 Slide adapted from Goodrich & Tamassia

23 Slide adapted from Goodrich & Tamassia

24 Weighted Graphs

25 Slide adapted from Goodrich & Tamassia

26 Slide adapted from Goodrich & Tamassia

27 Greedy Algorithms An algorithm which always takes the best immediate, or local, solution in looking for an answer. Greedy algorithms sometimes find less-than- optimal solutions Some greedy algorithms always find the optimal solution –Dijkstra’s shortest paths algorithm –Prim’s algorithm for minimum spanning trees

28 Slide adapted from Goodrich & Tamassia An animation

29 Slide adapted from Goodrich & Tamassia

30 Slide adapted from Goodrich & Tamassia

31 Slide adapted from Goodrich & Tamassia

32 Slide adapted from Goodrich & Tamassia

33 Slide adapted from Goodrich & Tamassia

34 Slide adapted from Goodrich & Tamassia

35 Slide adapted from Goodrich & Tamassia

36 Slide adapted from Goodrich & Tamassia

37 This algorithm uses a forest of trees. – Initially the forest consists of n single node trees (and no edges). –At each step, we add one (the cheapest one) edge so that it joins two trees together. –If it were to form a cycle, it would simply link two nodes that were already part of a single connected tree, so we don’t use the edge in this case. Kruskal’s Minimum Spanning Tree

38 Kruskal’s Minimum Spanning Tree

39 Kruskal’s Minimum Spanning Tree (cont)

40 Kruskal’s Minimum Spanning Tree (cont) An animation of Kruskal’s