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

Graph problems Prof. Ramin Zabih

Embed Size (px)

DESCRIPTION

3 Some major graph problems  Graph coloring –Ensuring that radio stations don’t clash  Graph connectivity –How fragile is the internet?  Graph cycles –Helping FedEx/UPS/DHL plan a route  Planarity testing –Connecting computer chips on a motherboard  Graph isomorphism –Is a chemical structure already known?

Citation preview

Page 1: Graph problems Prof. Ramin Zabih

Graph problems

Prof. Ramin Zabih

http://cs100r.cs.cornell.edu

Page 2: Graph problems Prof. Ramin Zabih

2

Administrivia Assignment 2 is due Friday

– Working Roomba’s are on the way (?) Quiz 3 on Tuesday 9/25

– Coverage through next lecture Optional lecture topics are ready

– First one will be RDZ talking about graphs• Graph questions are favorites for interviewers (at

places like Google and Microsoft)

Page 3: Graph problems Prof. Ramin Zabih

3

Some major graph problems Graph coloring

– Ensuring that radio stations don’t clash Graph connectivity

– How fragile is the internet? Graph cycles

– Helping FedEx/UPS/DHL plan a route Planarity testing

– Connecting computer chips on a motherboard Graph isomorphism

– Is a chemical structure already known?

Page 4: Graph problems Prof. Ramin Zabih

4

How to represent graphs? The adjacency matrix A is n by n

– We will give each vertex a number 1..n– A(r,c) == 1 when there is an edge between

vertex r and vertex c– Note that A(r,c) == A(c,r)

0 0 1 0 00 0 0 0 11 0 0 1 00 0 1 0 00 1 0 0 0

V1V2

V3

V4

V5

Page 5: Graph problems Prof. Ramin Zabih

5

Given a graph and a set of colors {1..k} We want to assign each vertex a color

– Two adjacent vertices have different colors

Graph coloring problem

V1V2

V3

V4

V5

Page 6: Graph problems Prof. Ramin Zabih

6

Radio frequencies via coloring Make a graph where a station is a vertex

– Put an edge between two stations that clash• I.e., if their signal areas overlap

– Any coloring is a non-clashing layout• Can you prove this? What about vice-versa?

C1C2

C3

C4

C5

Page 7: Graph problems Prof. Ramin Zabih

7

Verifying vs. finding One theme we’ve seen is that it can be

easy to verify you have the right answer– I.e., prove that your candidate is the solution– Example: sorting

If this is easy, there is a dumb algorithm– Guess and verify– Or: try everything

It’s not always easy to verify that an answer is correct– Example: is this graph 4-colorable?

Page 8: Graph problems Prof. Ramin Zabih

8

Graphs and paths Can you get from vertex V to vertex W?

– Is there a route from one city to another? More precisely, is there a sequence of

vertices {V,V1,V2,…,Vk,W} such that every adjacent pair has an edge between them– This is called a path– A cycle is a path from V to V– A path is simple if no vertex appears twice

Page 9: Graph problems Prof. Ramin Zabih

9

Graph connectivity For any pair of nodes, is there a path

between them?– Basic idea of the Internet: you can get from

any computer to any other computer– This pair of nodes is called connected

• A set of nodes is connected if all pairs are– A graph is connected if all nodes are connected

Related question: if I remove an arbitrary node, is the graph still connected?– Is the Internet intact if any 1 computer fails?

Page 10: Graph problems Prof. Ramin Zabih

10

Connected components Even if all nodes are not connected, there

will be subsets that are all connected– Connected components

– All nodes are connected– Is this sufficient? Why not?

V5V4V1

V3

V2

Page 11: Graph problems Prof. Ramin Zabih

11

Blobs are components!A 0 0 0 0 0 0 0 B 00 0 0 0 0 0 0 0 C 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 D 0 0 0 0 00 0 0 E F G 0 0 0 00 0 0 H 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0

A CB

DF E

HG