340 likes | 732 Views
Part 10. Graphs. CS 200 Algorithms and Data Structures. Outline. Introduction Terminology Implementing Graphs Graph Traversals Topological Sorting Shortest Paths Spanning Trees Minimum Spanning Trees Circuits. Circuits. Cycle
E N D
Part 10. Graphs CS 200 Algorithms and Data Structures
Outline • Introduction • Terminology • Implementing Graphs • Graph Traversals • Topological Sorting • Shortest Paths • Spanning Trees • Minimum Spanning Trees • Circuits
Circuits • Cycle • A special cycle that passes through every vertex (or edge) in a graph exactly once and returns back to the place it started.
Euler’s bridge problem (Bridges of Konigsberg Problem) River Bank A Edge Between A and D Edge Between A and C Edge Between A and C Island C Edge Between C and D Island D Edge Between B and C Euler River Bank B Edge Between B and D Edge Between B and C Is it possible to travel across every bridge without crossing any bridge more than once? http://yeskarthi.wordpress.com/2006/07/31/euler-and-the-bridges-of-konigsberg
Euler’s bridge problem (Bridges of Konigsberg Problem) Euler Is it possible to travel across every bridge without crossing any bridge more than once? http://yeskarthi.wordpress.com/2006/07/31/euler-and-the-bridges-of-konigsberg
Euler paths/circuits • Euler path: A path that visits each edge only once in the graph • Euler circuit: A cycle that visits each edge only once in the graph
Example: Does any graph have an Euler circuit? e b b b a a a e e d d d c c c
Example: Does any graph have an Euler path? e b b b a a a e e d d d c c c
Example: Does any graph have an Euler circuit? b a a b g d c c b a f e d d c
Euler paths/circuits • Is there a simple criterion that allows us to determine whether a graph has an Euler circuit or path?
Euler Paths • Theorem: A connected multigraph has an Euler path .iff. it has exactly two vertices of odd degree
Euler Circuits • Theorem: A connected multigraph with at least two vertices has an Euler circuit .iff. each vertex has an even degree.
Mohammed’s Scimitars j a i e f h b g d c k Can Mohammed’s scimitars be drawn without lifting a pencil and the drawing begins and ends at the same point? a-e-f-i-e-b-c-d-g-h-j-i-k-g-d-b-a
Hamiltonian Paths/Circuits • A Hamiltonian path/circuit:path/circuit that visits every vertex exactly once. • Defined for directed and undirected graphs. • Is there an efficient way to determine whether a graph has a Hamiltonian circuit?
Does any graph have a Hamiltonian circuit or a Hamiltonian path? b a b a d c d c e b a e d c
DIRAC’s Theorem • If G is a simple graph with n vertices with n≥3 such that the degree of every vertex in G is at least n/2, then G has a Hamiltonian circuit.
Ore’s Theorem • If G is a simple graph with n vertices with n≥3 such that deg(u)+deg(v)≥n for every pair of nonadjacent vertices u and v in G, then G has a Hamiltonian circuit.
Hamiltonian Paths/Circuits • Direc and Ore’s theorems provide sufficient condition for a connected simple graph to have a Hamiltonian circuit. • They do NOT provide necessary condition for the existence of a Hamiltonian circuit • This problem belongs to a class of problems for which it is believed there is no efficient (polynomial running time) algorithm.
The Traveling Salesman Problem (TSP) Can we use the Shortest path algorithm? Can we use the Euler Circuit? TSP: Given a list of cities and their pairwise distances, find a shortest possible tour that visits each city exactly once. Can we use the Hamilton Circuit? 13,509 cities and towns in the US that have more than 500 residents An optimal TSP tour through Germany’s 15 largest cities (one out of 14!/2) http://www.tsp.gatech.edu/
Using Hamiltonian Circuits • Examine all possible Hamiltonian circuits and select one of minimum total length • With n cities.. • (n-1)! Different Hamiltonian circuits • Ignore the reverse ordered circuits • (n-1)!/2 • With 50 cities • 12,413,915,592,536,072,670,862,289,047,373,375,038,521,486,354,677,760,000,000,000 routes
The three utilities problem House A House B ? House C
Designing a Microchip • You are designing a microchip – connections between any two units cannot cross http://www.dmoma.org/
Planar Graphs • You are designing a microchip – connections between any two units cannot cross • The graph describing the chip must be planar planar non-planar http://en.wikipedia.org/wiki/Planar_graph
Chip Design • You want more than planarity: the lengths of the connections need to be as short as possible (faster, and less heat is generated) http://www.dmoma.org/
Euler’s Formula • Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G. Then r=e-v+2
Example • Suppose that a connected planar simple graph has 20 vertices, each of degree 3. Into how many regions does a representation of this planar graph split the plane?
Graph Coloring • A coloring of a simple graph is the assignment of a color to each vertex of the graph so that no two adjacent vertices are assigned the same color
Map and graph B A C D D G B F C A F E E G
Chromatic number • The least number of colors needed for a coloring of this graph. • The chromatic number of a graph G is denoted by χ(G)
The four color theorem • The chromatic number of a planar graph is no greater than four
Example • What is the chromatic number of the graph Cn, where n>=3? (Cn is the cycle with n vertices)