Connected components and graph traversal Prof. Noah Snavely CS1114

Slides:



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

Great Theoretical Ideas in Computer Science
Great Theoretical Ideas in Computer Science for Some.
Tutorial 5 of CSCI2110 Eulerian Path & Hamiltonian Cycle Tutor: Zhou Hong ( 周宏 )
Graph algorithms Prof. Noah Snavely CS1114
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Great Theoretical Ideas in Computer Science for Some.
CompSci 102 Discrete Math for Computer Science April 19, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
GRAPHS Trees Without Rules. Graph  A data structure that consists of a set of nodes (called vertices) and a set of edges that relate the nodes to each.
Sociology and CS Philip Chan. How close are people connected? Are people closely connected, not closely connected, isolated into groups, …
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.
Graph.
Great Theoretical Ideas in Computer Science.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R5. Graphs.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Linked lists Prof. Noah Snavely CS1114
Great Theoretical Ideas in Computer Science.
1 CIS /204—Spring 2008 Recitation 10 Friday, April 4, 2008.
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)
Blobs and Graphs Prof. Noah Snavely CS1114
New Algorithm DOM for Graph Coloring by Domination Covering
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Eulerian Graphs CSE 331 Section 2 James Daly. Reminders Project 3 is out Covers graphs Due Friday.
9.2 Graph Terminology and Special Types Graphs
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
 Jim has six children.  Chris fights with Bob,Faye, and Eve all the time; Eve fights (besides with Chris) with Al and Di all the time; and Al and Bob.
Chapter 2 Graph Algorithms.
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Connected Components Fun with graphs, searching, and queues.
Mathematics of Networks (Cont)
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Medians and blobs Prof. Ramin Zabih
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.
Graphs and 2-Way Bounding Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1 /File:7_bridgesID.png.
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
Eulerian Paths and Cycles. What is a Eulerian Path Given an graph. Find a path which uses every edge exactly once. This path is called an Eulerian Path.
Chapter 6: Graphs 6.1 Euler Circuits
Breadth-first and depth-first traversal Prof. Noah Snavely CS1114
Chapter 9: Graphs.
CS 261 – Nov. 17 Graph properties – Bipartiteness – Isomorphic to another graph – Pseudograph, multigraph, subgraph Path Cycle – Hamiltonian – Euler.
Breadth-first and depth-first traversal CS1114
Graph problems Prof. Ramin Zabih
COMPSCI 102 Introduction to Discrete Mathematics.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
Week 10 - Wednesday.  What did we talk about last time?  Counting practice  Pigeonhole principle.
Blobs and Graphs Prof. Noah Snavely CS1114
Data Structures Graphs - Terminology
CSC 172 DATA STRUCTURES.
Graph theory Definitions Trees, cycles, directed graphs.
Great Theoretical Ideas in Computer Science
CS120 Graphs.
Planarity Testing.
Discrete Mathematics for Computer Science
CSC 172 DATA STRUCTURES.
Data Structures – Stacks and Queus
Graphs Chapter 13.
Decision Maths Graphs.
Richard Anderson Winter 2009 Lecture 6
Breadth-First Search L0 L1 L2 C B A E D F Breadth-First Search
Richard Anderson Lecture 5 Graph Theory
Prof. Ramin Zabih Graph Traversal Prof. Ramin Zabih
Presentation transcript:

Connected components and graph traversal Prof. Noah Snavely CS1114

2 Administrivia  Assignment 2 is out –First part due tomorrow by 5pm –Second part due next Friday by 5pm  First prelim will be in two weeks –Thursday, February 26, in class

3 What is a graph?  Loosely speaking, a set of things that are paired up in some way  Precisely, a set of vertices V and edges E –Vertices sometimes called nodes –An edge (or link) connects a pair of vertices V1 V2 V3 V4 V5 V = { V1, V2, V3, V4, V5 } E = { (V1,V3), (V2,V5), (V3,V4) }

Images as graphs 4

5

6

More graph problems 7

8 Hamiltonian & Eulerian cycles  Two questions that are useful for problems such as mailman delivery routes  Hamiltonian cycle: –A cycle that visits each vertex exactly once (except the start and end)  Eulerian cycle: –A cycle that uses each edge exactly once

Hamiltonian & Eulerian cycles 9 V5 V1 V2 V4V3 V10 V6 V7 V9V8  Is it easier to tell if a graph has a Hamiltonian or Eulerian cycle?

10 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

11  Is this graph planar? V1V2V3V4V5V6  Can you prove it?

12 Four-color theorem  Any planar graph can be colored using no more than 4 colors

“Small world” phenomenon (Six degrees of separation)  How close together are nodes in a graph (e.g., what’s the average number of hops connecting pairs of nodes?) 13  Milgram’s small world experiment: Send postcard to random person A in Omaha; task is to get it to a random person B in Boston If A knows B, send directly Otherwise, A sends to someone A knows who is most likely to know B People are separated by 5.5 links on average

14 Friend wheel

Another graph 15

Graph of Flickr images 16 Flickr images of the Pantheon, Rome (built 126 AD) Images are matched using visual features

Image graph of the Pantheon 17

18 Connected components  Even if all nodes are not connected, there will be subsets that are all connected –Connected components –Component 1: { V1, V3, V5 } –Component 2: { V2, V4 } V5 V4 V1 V3 V2

Blobs are components! 19

20 Blobs are components! A B C D EFG H A C B D F E H G

21 Finding blobs 1.Pick a 1 to start with, where you don’t know which blob it is in –When there aren’t any, you’re done 2.Give it a new blob color 3.Assign the same blob color to each pixel that is part of the same blob

22 Finding components 1.Pick a 1 to start with, where you don’t know which component it is in –When there aren’t any, you’re done 2.Give it a new component color 3.Assign the same component color to each pixel that is part of the same component –Basic strategy: color any neighboring 1’s, have them color their neighbors, and so on

23 Coloring a component

24 Coloring a component

25 Coloring a component

26 Coloring a component

27 Strategy  For each vertex we visit, we color its neighbors and remember that we need to visit them at some point –Need to keep track of the vertices we still need to visit in a todo list –After we visit a vertex, we’ll pick one of the vertices in the todo list to visit next

A BCD EFG HIJ KLM Current node: A Todo List: [ ]

A BCD EFG HIJ KLM Current node: A Todo List: [ C ] Done with A, choose next from Todo List

A BCD EFG HIJ KLM Current node: C Todo List: [ ]

A BCD EFG HIJ KLM Current node: C Todo List: [ B, F, D ]

A BCD EFG HIJ KLM Current node: B Todo List: [ F, D ]

A BCD EFG HIJ KLM Current node: B Todo List: [ F, D, E ]

34 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 Pick one to visit next, keep track of the rest

35 Graph traversal  Select an uncolored vertex, add it to the todo list  While the todo list is not empty –Remove a vertex V from the todo list –Add the uncolored neighbors of V to the todo list and color them

36 Stacks and Queues  One way to implement the todo list is as 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…  The alternative is a queue –FIFO: First In First Out –Think of a line of (well-mannered) people –First come, first served

Next time  More on stacks and queues 37