Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 200 Algorithms and Data Structures

Similar presentations


Presentation on theme: "CS 200 Algorithms and Data Structures"— Presentation transcript:

1 CS 200 Algorithms and Data Structures
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 River Bank B Edge Between B and D Euler Edge Between B and C Is it possible to travel across every bridge without crossing any bridge more than once?

5 Euler’s bridge problem (Bridges of Konigsberg Problem)
Is it possible to travel across every bridge without crossing any bridge more than once?

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?
b c d e a b c d a b c d e e

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

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

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 e i f b h 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 c d e a b c d a b c d e

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)

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

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

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)

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 A B C D G E F B A C D E F 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)


Download ppt "CS 200 Algorithms and Data Structures"

Similar presentations


Ads by Google