Prof. Ramin Zabih http://cs100r.cs.cornell.edu Graph Traversal Prof. Ramin Zabih http://cs100r.cs.cornell.edu.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Graph algorithms Prof. Noah Snavely CS1114
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Theory of Computing Lecture 18 MAS 714 Hartmut Klauck.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Decision Maths Graphs Wiltshire Graphs A graph is just a diagram made up of “dots” and “lines”. These are all graphs. The dots are called “nodes” or.
Last time: terminology reminder w Simple graph Vertex = node Edge Degree Weight Neighbours Complete Dual Bipartite Planar Cycle Tree Path Circuit Components.
Graph Traversals Reading Material: Chapter 9. Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
CS 1114: Graphs and Blobs Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Connected components and graph traversal Prof. Noah Snavely CS1114
GRAPH Learning Outcomes Students should be able to:
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Connected Components Fun with graphs, searching, and queues.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
COSC 2007 Data Structures II
Breadth-first and depth-first traversal CS1114
Graph problems Prof. Ramin Zabih
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
Breadth-First Search (BFS)
Graphs – Breadth First Search
More NP-complete problems
IOI/ACM ICPC Training 4 June 2005.
Graphs Chapter 20.
EECS 203 Lecture 19 Graphs.
BackTracking CS255.
A vertex u is reachable from vertex v iff there is a path from v to u.
Data Structures Graphs - Terminology
Graphs-Part II Depth First Search (DFS)
CSC 172 DATA STRUCTURES.
Graph Traversals Some algorithms require that every vertex of a graph be visited exactly once. The order in which the vertices are visited may be important,
Great Theoretical Ideas In Computer Science
CSC317 Graph algorithms Why bother?
Csc 2720 Instructor: Zhuojun Duan
Graph theory Definitions Trees, cycles, directed graphs.
EECS 203 Lecture 20 More Graphs.
Lecture 12 Graph Algorithms
Great Theoretical Ideas in Computer Science
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
CS120 Graphs.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Discrete Mathematics for Computer Science
CSE 421: Introduction to Algorithms
CSC 172 DATA STRUCTURES.
Data Structures – Stacks and Queus
Graphs Chapter 13.
Lecture 13 CSE 331 Sep 27, 2017.
CSE 373 Data Structures Lecture 16
Spanning Trees Longin Jan Latecki Temple University based on slides by
Richard Anderson Autumn 2016 Lecture 5
Decision Maths Graphs.
Richard Anderson Winter 2009 Lecture 6
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
A vertex u is reachable from vertex v iff there is a path from v to u.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Discrete Mathematics for Computer Science
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Richard Anderson Winter 2019 Lecture 6
Richard Anderson Winter 2019 Lecture 5
Lecture 13 CSE 331 Sep 28, 2016.
Concepts of Computation
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:

Prof. Ramin Zabih http://cs100r.cs.cornell.edu Graph Traversal Prof. Ramin Zabih http://cs100r.cs.cornell.edu

Administrivia Assignment 2 is due Friday Quiz 3 on Tuesday 9/25 Working Roomba’s are on the way (?) Quiz 3 on Tuesday 9/25 Coverage through today

Hamiltonian & Eulerian cycles Two questions that are useful for problems such as mailman delivery routes Is there a path that goes through each vertex exactly once? Hamiltonian cycle Is there a path that uses each edge exactly once? Eulerian cycle Which is easier to compute?

Colorings and cliques A clique is a set of vertices which are all connected to each other If there is a clique with 4 vertices, what can you say about coloring the graph? Need at least 4 colors With enough colors, can color any graph Each vertex gets a different color

Independent set An independent set is a set of vertices where no pair is connected by an edge In a coloring, each color is an independent set How can you schedule your classes via independent set? Nodes are classes, edges connect classes that conflict with each other “I can take M classes” iff “the graph has an independent set of size M” This implies you can take <M classes also

Planarity testing A graph is planar if you can draw it without the edges crossing It’s OK to move the edges or vertices around, as long as edges connect the same vertices V1 V2 V3 V4 V5

 Is this graph planar? V1 V4 V2 V5 V3 V6  Can you prove it?

Four-color theorem Any planar graph can be colored using no more than 4 colors I.e., consider a map, where you want adjacent countries to be different colors Heavily computer-aided proof

Blob = connected component A B C D E F G H A C B D F E H G

Where to visit next? 1 X C B A D Y E

Strategy We need to keep track of the vertices we need to “visit” (possibly label with our blob number) Although, by the time we get there, they may already have been labeled Visit A, and label it Need to visit its neighbors: B, C, D, E Pick one to visit next, keep track of the rest Visit B, and label it Need to visit its neighbors X, Y

Graph traversal Visit every vertex in our current component, giving it the label L While there is a vertex V that we have not yet given a label Add V to our “to-do” collection C While C is not empty Take a vertex V’ out of C Give it label L, if it doesn’t have this label yet Add the unlabeled neighbors of V’ to C Why is this important?

Graphs and trees A graph is a tree if it has no cycles Start at V1 We are only considering undirected graphs Start at V1 Put V1 in C Take, label V1 Put V2, V3 in C Take, label V2 Put V4, V5 in C Now what?? V2 V1 V3 V4 V5 V6

Stacks and Queues The obvious ways to implement our collection C is a stack LIFO, Last In First Out Think of a pile of trays in a cafeteria Trays at the bottom can stay there a while… Other alternative is a queue FIFO, First In First Out Think of a line of (well-mannered) people First come, first served

Two basic traversal orders Depth-first Stack Breadth-first Queue Animations taken from: http://www.rci.rutgers.edu/~cfs/472_html/AI_SEARCH/ExhaustiveSearch.html