1 / 33

Part 10. Graphs

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

johana
Download Presentation

Part 10. Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Part 10. Graphs CS 200 Algorithms and Data Structures

  2. Outline • Introduction • Terminology • Implementing Graphs • Graph Traversals • Topological Sorting • Shortest Paths • Spanning Trees • Minimum Spanning Trees • Circuits

  3. 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.

  4. 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

  5. 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

  6. 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

  7. Example: Does any graph have an Euler circuit? e b b b a a a e e d d d c c c

  8. Example: Does any graph have an Euler path? e b b b a a a e e d d d c c c

  9. Example: Does any graph have an Euler circuit? b a a b g d c c b a f e d d c

  10. Euler paths/circuits • Is there a simple criterion that allows us to determine whether a graph has an Euler circuit or path?

  11. Euler Paths • Theorem: A connected multigraph has an Euler path .iff. it has exactly two vertices of odd degree

  12. Euler Circuits • Theorem: A connected multigraph with at least two vertices has an Euler circuit .iff. each vertex has an even degree.

  13. 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

  14. 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?

  15. 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

  16. 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.

  17. 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.

  18. 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.

  19. 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/

  20. 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

  21. The three utilities problem House A House B ? House C

  22. Designing a Microchip • You are designing a microchip – connections between any two units cannot cross http://www.dmoma.org/

  23. 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

  24. Is this graph planar?

  25. 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/

  26. 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

  27. 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?

  28. 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

  29. Map and graph B A C D D G B F C A F E E G

  30. 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)

  31. The four color theorem • The chromatic number of a planar graph is no greater than four

  32. Example

  33. Example • What is the chromatic number of the graph Cn, where n>=3? (Cn is the cycle with n vertices)

More Related