Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graph Theory.

Similar presentations


Presentation on theme: "Graph Theory."— Presentation transcript:

1 Graph Theory

2 Graphs Graph theory is a key part of computer science and computer science algorithms Example: The traveling salesperson problem Can we find the shortest path through a set of cities that visits each city once and starts and ends at the same city? FYI: this is a famous problem and there is no known algorithm (set of steps) that is guaranteed to solve it in all cases, other than trying all possible paths (which is not very efficient)

3 Definitions A graph is a pair of sets, V and E Example:
V is the set of vertices E is the set of edges Example: V = {A, B, C, D} E = {(A,B), (A,C), (C,D), (A,D), (B,C)} What does the graph look like? You need to be able to take a graph and represent it using V and E or take V and E and draw the graph

4 The Example Graph V = {A, B, C, D}
E = {(A,B), (A,C), (C,D), (A,D), (B,C)}

5 More definitions A path is a sequence of vertices v1, v2, .., vn such that (vi, vi+1) is in E an no vertices are repeated The length of the path is the number of edges in between the starting and ending vertex. A path may be undirected if you can travel along an edge in either direction (as in the last example) or may be directed, in which case you should include arrows A graph may be weighted in which case there is a weight associated with each edge. What might the weight represent for the traveling salesman problem? The degree of a vertex is the number of edges it has

6 And More Definitions An undirected graph is connected if there is a path from every vertex to every other vertex G is a subgraph of H if all vertices & edges in G are in H A maximally connected component is a connected subgraph such that no vertices can be added and have it still be connected

7 Examples A E B D F C Give 3 examples of paths and specify their lengths Are these graphs undirected or directed? Are they unweighted or weighted? What is the degree of each node? Is the graph connected? Why or why not? List 3 subgraphs. List two maximally connected components of the graph

8 Euler Paths Euler path: Find a path that visits every edge in the graph exactly once Euler circuit: An Euler path that starts and ends at the same vertex Same problems as asking you to trace all of the edges without lifting your pencil Can you come up with any simple rules that might help you decide whether a graph has or does not have an Euler path or Euler circuit?

9 Determining Euler Paths/Circuits
If a graph has an Euler circuit, the degree of every vertex must be even Can’t get stuck at any vertex Converse is true: if the degree of every vertex in a connected graph is even, then must have an Euler circuit A graph has an Euler path if every vertex has an even degree or has exactly two with odd degree.

10 Euler Circuit Examples
Which one(s) have an Euler Circuit? Which one(s) have an Euler Path? Only the rightmost one has an Euler Circuit Only the middle one does not have an Euler path

11 Hamiltonian Circuits Euler circuits are about visiting each edge exactly once. Hamiltonian paths/circuits are about visiting each vertex only once. A Hamiltonian circuit is a cycle (path need not be) There is no method/algorithm for determining whether a graph has a Hamiltonian circuit. Traveling salesman problem is for a weighted graph where we must find the minimum Hamiltonian path.

12 What you need to know for the exam
Know everything on these slides The basic definitions I may ask you if a graph has an Euler circuit I may even ask you if it has a Hamiltonian circuit (you would need to figure that out by trial and error) I could ask you something new based on the basic definitions (e.g., shortest path between two points)


Download ppt "Graph Theory."

Similar presentations


Ads by Google