 # Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.

## Presentation on theme: "Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1."— Presentation transcript:

Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1

What is a graph? 2

3

4

Graphs – Are they really important?? Yes! Used in virtually EVERY discipline! Common examples Airline routes – draw lines between cities Computer networks – lines for direct connection Workforce – People & Jobs assigned Travel – Cities & highways 5

What is a graph? Non-technical definition: Set of objects in which some pairs are related DEFN: Graph Collection of Vertices (V) & Edges (E). Vertices are simple objects & an Edge is a connection between 2 Vertices Non-empty, finite set of vertices (V) & set of edges (e) of 2-element subsets (pairs) of V Note: Graph Theory terminology is not always consistent among books/authors 6

What is a graph? Author’s restrictions No edge from vertex to itself Only one edge between 2 specific vertices Makes graphs simpler But is BIG restriction Other Examples??? 7

Graph Terminology Vertices are generally named – a, b, c… Edges usually named by 2 vertices – (a,b) Edges may be labeled – usually a value Value = distance, cost, etc. Adjacent, Joined: 2 vertices are adjacent/joined if they are connected by an edge Incident: a vertex & edge are incident if the edge connects to the vertex 8

Example Vertex Edge Label Value Adjacent Incident 9

More Terms Degree of Vertex: Number of edges incident to the vertex Degree of Graph: Maximum of degrees of vertices Complete Graph: Every vertex is adjacent to every other vertex an edge exists between each pair of vertices 10

Interpretation of a Graph NOTE: The shape of a graph is not “important” it is the relationship that is significant. A single graph can be drawn multiple ways but still represents the same relationships. PROBLEM: Given a graph, can it be drawn without any of the edges crossing? 11

Number of Vertices How many edges are in a complete graph of N vertices? Can we solve inductively? Can we develop the table? VerticesEdges 10 21 33 46 510 615 N??? 12

Theorem 4.1 In a graph the sum of the degrees of the vertices equals twice the number of edges. Why? Because each 1 edge is incident on 2 vertices. 13

Graph Representation: Adjacency Matrix Given a graph with N vertices, form an NXN matrix with rows & columns labeled to represent the vertices. Place a 1 in location (i, j) if there is an edge between Vertices i and j, and place a 0 otherwise. V1V2V3V4 V10110 V21001 V31001 V40110 14

Graph Representation: Adjacency List List (array) containing each vertex, attached to a (linked) list of each vertex adjacent to it 15 V1V2V3 V2 V4 V3V1V3 V4V2V3

Isomorphic Graphs Two graphs G1 & G2 are isomorphic if there exists a 1-to-1 correspondence f between the vertices of graphs such that if vertices u & v are adjacent in G1 then f (u) and f (v) are adjacent in G2 I.E. Graphs are the same except for labeling & arrangement 16

Isomorphic Graphs The following graphs are isomorphic Colors indicate the 1-to-1 correspondence 17

18 Determining Isomorphism How could we determine if 2 graphs G1 & G2 are isomorphic? This is a “hard” problem. (More later!) Can we determine if 2 Graphs G1 & G2 are NOT isomorphic?

19 Determining Isomorphism Invariant – a term that states some fact that does not vary State isomorphic graph invariants: What properties must be true of 2 graphs if they are isomorphic.

20 Determining Isomorphism Invariant – a term that states some fact that does not vary State isomorphic graph invariants: What properties must be true of 2 graphs if they are isomorphic? Equal number of vertices Equal number of edges Vertices have same degree

21 Homework Section 4.1 All 1 - 50

22 4.2 Paths & Circuits Multigraph: Graph which has parallel edges between vertices and/or loops Loop: Edge from a vertex to itself Degree is counted as 2 for a loop Parallel Edges: Multiple edges between 2 vertices Path: a path from vertices U to V is a sequence of vertices & edges from U to V Simple Path: no repeated edge or vertex Length of Path (from U to V): number of edges in the path from U to V

23 Example Multigraph Loop Degree (of node with loop) Parallel Edges Path Length of Pat

24 More Terminology Connected: a graph in which there is a path between each pair of vertices Cycle: a path of length >0 which begins & ends at the same vertex all edges & non-ending vertices are distinct

25 Euler Paths & Circuits Euler Path: a path including every edge exactly once & different first & last vertices Euler Circuit: a path including every edge exactly once & the same first & last vertices See examples on pages 165 - 168

26 Existence of Euler Circuit Graph must be connected Each vertex reached must be exited – thus must have degree 2 (in & out) If a vertex is visited multiple times must have even number of vertices Example 4.20 – page 168 Euler Circuit Algorithm (pg. 169-170)

27 Euler Circuit Algorithm - Overview Select any vertex – U Randomly select unused edges to construct circuit from U to U If unselected edges remain, Select a vertex with unselected edge & construct a circuit Repeat until all edges are included Note: not a unique solution

28 Euler Circuit - Implementation How is graph represented? How do you mark edges as selected? How do you know if unselected edges remain? Sets… E is set of edges P is path

29 Theorem 4.5 Necessary & sufficient conditions for Euler circuit - path Suppose a multigraph G is connected. G has an Euler circuit iff every vertex has even degree. G has an Euler path iff every vertex has even degree except for 2 distinct vertices which have odd degree (Path begins at one odd vertex & ends at the other)

30 Complexity of Euler Circuit Algorithm for a connected graph Let “selecting an edge” be a basic operation. Since e edges, complexity is O(e) For graph with n vertices, what is max e for any given vertex? e <= ½ n (n-1) = ½ (n 2 – n)  O(n 2 ) What about a multigraph?

31 Hamiltonial Cycles & Paths Hamiltonian Path: Path containing each vertex of a graph exactly once Hamiltonian Cycle: Cycle containing each vertex of a graph exactly once Figures 4.1 (154) & 4.22 (172)

32 Existence of Hamiltonian Cyles & Paths Unsolved Problem: necessary & sufficient conditions for Hamiltonian Cycle & Path Hard to find even if know of existence Theorem 4.6 S’pose G is a graph with n >2 vertices. If each pair of non-adjacent vertices U & V satisfy deg(U) + deg(V) >= n then G has a Hamiltonian Cycle.

33 Extension of Theorem 4.6 Existence of Hamiltonial Cycle S’pose graph G has n vertices and every vertex has degree >= n/2. G has a Hamiltonial Cycle. WHY??? But still have no algorithm for finding it.

34 More on Theorem 4.6 Failing Theorem 5.6 does not mean a Hamiltonian Cycle does not exist. None of non-adjacent vertices have degree n/2, but Hamiltonian Cycle exists

35 Homework Section 4.2 Page 176 + Problems 1 – 29, 35 – 38, 60 Rest of chapter in separate file

Download ppt "Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1."

Similar presentations