Download presentation
Presentation is loading. Please wait.
1
Graph & Trees Chapters 10-11
Discrete Mathematics 12/4/2018 Graph & Trees Chapters 10-11 Acknowledgement This is a modified version of Module#22 on Graph Theory by Michael Frank Sultan Almuhammadi ICS 254: Graphs and Trees ICS 254: Graphs and Trees
2
What are Graphs? Not General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete mathematics: A particular class of discrete structures (to be defined) that is useful for representing relations and has a convenient webby-looking graphical representation. Sultan Almuhammadi ICS 254: Graphs and Trees
3
Applications of Graphs
Potentially anything (graphs can represent relations, relations can describe the extension of any predicate). Apps in networking, scheduling, flow optimization, circuit design, path planning. More apps: Geneology analysis, computer game-playing, program compilation, object-oriented design, … Sultan Almuhammadi ICS 254: Graphs and Trees
4
§10.1: Definition of Graph A graph G = (V, E)
V is a nonempty set of verticies E is a set of edges (arcs or links) between vertices Type of edges: Directed: ordered pairs (u, v) of vertices Undirected: unordered pairs {u, v} of vertices Sultan Almuhammadi ICS 254: Graphs and Trees
5
Visual Representation of a Simple Graph
Simple Graphs A simple graph G=(V,E) consists of: a set V of vertices or nodes (V corresponds to the universe of the relation R), a set E of edges: unordered pairs of [distinct] vertices u,v V Visual Representation of a Simple Graph Sultan Almuhammadi ICS 254: Graphs and Trees
6
Example of a Simple Graph
Let V be the set of the 6 GCC states: V={KSA, UAE, KWT, OMN, QTR, BAH} Let E={{u,v}| u adjoins v} E ={{KSA,UAE}, {KSA,KWT}, {KSA,BAH}, {KSA,QTR}, {UAE,OMN}} Sultan Almuhammadi ICS 254: Graphs and Trees
7
Multigraphs Like simple graphs, but there may be more than one edge connecting two given nodes. E.g., nodes are cities, edges are segments of major highways between the cities. Parallel edges Sultan Almuhammadi ICS 254: Graphs and Trees
8
Pseudographs Like a multigraph, but edges connecting a node to itself are allowed. (R may be reflexive.) A pseudograph G=(V, E) where Edge eE is a loop if e = {u, u} = {u}. E.g., nodes are the cities in a state, edges are the roads serving/connecting the cities. loops Sultan Almuhammadi ICS 254: Graphs and Trees
9
Directed Graphs Correspond to arbitrary binary relations R, which may not be symmetric. A directed graph (V,E) consists of a set of vertices V and a binary relation E on V. E.g.: V = set of People, E={(x,y) | x loves y} Sultan Almuhammadi ICS 254: Graphs and Trees
10
Directed Multigraphs Like directed graphs, but there may be more than one arc from a node to another. E.g., V=web pages, E=hyperlinks. The WWW is a directed multigraph... Sultan Almuhammadi ICS 254: Graphs and Trees
11
Types of Graphs: Summary
Summary of the book’s definitions. Keep in mind this terminology is not fully standardized across different authors... Sultan Almuhammadi ICS 254: Graphs and Trees
12
§10.2: Graph Terminology You need to learn the following terms:
Adjacent, connects, endpoints, degree, initial, terminal, in-degree, out-degree, complete, cycles, wheels, n-cubes, bipartite, subgraph, union. Sultan Almuhammadi ICS 254: Graphs and Trees
13
Adjacency Let G be an undirected graph with edge set E. Let eE be (or map to) the pair {u,v}. Then we say: u, v are adjacent / neighbors / connected. Edge e is incident with vertices u and v. Edge e connects u and v. Vertices u and v are endpoints of edge e. Sultan Almuhammadi ICS 254: Graphs and Trees
14
Degree of a Vertex Let G be an undirected graph, vV a vertex.
The degree of v, deg(v), is its number of incident edges. (Except that any self-loops are counted twice.) A vertex with degree 0 is called isolated. A vertex of degree 1 is called pendant. Sultan Almuhammadi ICS 254: Graphs and Trees
15
Exercise Find: An element of degree 4 An element of degree 3 A pendant
An isolated vertix Sultan Almuhammadi ICS 254: Graphs and Trees
16
Handshaking Theorem Let G be an undirected (simple, multi-, or pseudo-) graph with vertex set V and edge set E. Then Corollary: Any undirected graph has an even number of vertices of odd degree. Sultan Almuhammadi ICS 254: Graphs and Trees
17
Directed Adjacency Let G be a directed (possibly multi-) graph, and let e be an edge of G that is (or maps to) (u,v). Then we say: u is adjacent to v, v is adjacent from u e comes from u, e goes to v. e connects u to v, e goes from u to v the initial vertex of e is u the terminal vertex of e is v Sultan Almuhammadi ICS 254: Graphs and Trees
18
Directed Degree Let G be a directed graph, v a vertex of G.
The in-degree of v, deg(v), is the number of edges going to v. The out-degree of v, deg(v), is the number of edges coming from v. The degree of v, deg(v):deg(v)+deg(v), is the sum of v’s in-degree and out-degree. Sultan Almuhammadi ICS 254: Graphs and Trees
19
Directed Handshaking Theorem
Let G be a directed (possibly multi-) graph with vertex set V and edge set E. Then: Note that the degree of a node is unchanged by whether we consider its edges to be directed or undirected. Sultan Almuhammadi ICS 254: Graphs and Trees
20
Special Graph Structures
Special cases of undirected graph structures: Complete graphs Kn Cycles Cn Wheels Wn n-Cubes Qn Bipartite graphs Complete bipartite graphs Km,n Sultan Almuhammadi ICS 254: Graphs and Trees
21
Complete Graphs For any nN, a complete graph on n vertices, Kn, is a simple graph with n nodes in which every node is adjacent to every other node: u,vV: uv{u,v}E. K1 K4 K2 K3 K5 K6 Note that Kn has edges. Sultan Almuhammadi ICS 254: Graphs and Trees
22
How many edges are there in Cn?
Cycles For any n3, a cycle on n vertices, Cn, is a simple graph where V={v1,v2,… ,vn} and E={{v1,v2},{v2,v3},…,{vn1,vn},{vn,v1}}. C3 C4 C5 C6 C8 C7 How many edges are there in Cn? Sultan Almuhammadi ICS 254: Graphs and Trees
23
How many edges are there in Wn?
Wheels For any n3, a wheel Wn, is a simple graph obtained by taking the cycle Cn and adding one extra vertex vhub and n extra edges {{vhub,v1}, {vhub,v2},…,{vhub,vn}}. W3 W4 W5 W6 W8 W7 How many edges are there in Wn? Sultan Almuhammadi ICS 254: Graphs and Trees
24
Number of vertices: 2n. Number of edges:Exercise to try!
n-cubes (hypercubes) For any nN, the hypercube Qn is a simple graph consisting of two copies of Qn-1 connected together at corresponding nodes. Q0 has 1 node. Q0 Q1 Q2 Q4 Q3 Number of vertices: 2n. Number of edges:Exercise to try! Sultan Almuhammadi ICS 254: Graphs and Trees
25
Bipartite Graphs Def’n.: A graph G=(V,E) is bipartite (two-part) iff V = V1 V2 where V1 ∩ V2= and eE: v1V1,v2V2: e={v1,v2}. In English: The graph can be divided into two parts in such a way that all edges go between the two parts. V1 V2 This definition can easily be adapted for the case of multigraphs and directed graphs as well. Can represent with zero-one matrices. Sultan Almuhammadi ICS 254: Graphs and Trees
26
Bipartite Graphs Exer: Are these graphs bipartite? G H
Sultan Almuhammadi ICS 254: Graphs and Trees
27
Complete Bipartite Graphs
For m,nN, the complete bipartite graph Km,n is a bipartite graph where |V1| = m, |V2| = n, and E = {{v1,v2}|v1V1 v2V2}. That is, there are m nodes in the left part, n nodes in the right part, and every node in the left part is connected to every node in the right part. K4,3 Km,n has _____ nodes and _____ edges. Sultan Almuhammadi ICS 254: Graphs and Trees
28
Subgraphs A subgraph of a graph G=(V,E) is a graph H=(W,F) where WV and FE. G H Sultan Almuhammadi ICS 254: Graphs and Trees
29
Graph Unions The union G1G2 of two simple graphs G1=(V1, E1) and G2=(V2,E2) is the simple graph (V1V2, E1E2). a b c d e a b c d f Sultan Almuhammadi ICS 254: Graphs and Trees
30
§10.3: Graph Representations & Isomorphism
Adjacency lists. Adjacency matrices. Incidence matrices. Graph isomorphism: Two graphs are isomorphic iff they are identical except for their node names. Sultan Almuhammadi ICS 254: Graphs and Trees
31
Adjacency Lists A table with 1 row per vertex, listing its adjacent vertices. b a d c e f Sultan Almuhammadi ICS 254: Graphs and Trees
32
Directed Adjacency Lists
1 row per node, listing the terminal nodes of each edge incident from that node. Sultan Almuhammadi ICS 254: Graphs and Trees
33
Adjacency Matrices A way to represent simple graphs
possibly with self-loops. Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, and is 0 otherwise. Can extend to pseudographs by letting each matrix elements be the number of links (possibly >1) between the nodes. Sultan Almuhammadi ICS 254: Graphs and Trees
34
Graph Isomorphism Formal definition:
Simple graphs G1=(V1, E1) and G2=(V2, E2) are isomorphic iff a bijection f:V1V2 such that a,bV1, a and b are adjacent in G1 iff f(a) and f(b) are adjacent in G2. f is the “renaming” function between the two node sets that makes the two graphs identical. This definition can easily be extended to other types of graphs. Sultan Almuhammadi ICS 254: Graphs and Trees
35
Graph Invariants under Isomorphism
Necessary but not sufficient conditions for G1=(V1, E1) to be isomorphic to G2=(V2, E2): We must have that |V1|=|V2|, and |E1|=|E2|. The number of vertices with degree n is the same in both graphs. For every proper subgraph g of one graph, there is a proper subgraph of the other graph that is isomorphic to g. Sultan Almuhammadi ICS 254: Graphs and Trees
36
Isomorphism Example If isomorphic, label the 2nd graph to show the isomorphism, else identify difference. d b a b a d c e e c f f Sultan Almuhammadi ICS 254: Graphs and Trees
37
Are These Isomorphic? If isomorphic, label the 2nd graph to show the isomorphism, else show an invariant property. Same # of vertices a b Same # of edges Different # of vertices of degree 2 (1 vs 3) d e c Sultan Almuhammadi ICS 254: Graphs and Trees
38
§10.4: Connectivity A path, p, from u to v is a sequence of adjacent edges going from vertex u to vertex v. e.g. p = (u,x), (x,y), …, (z,v) A path is a circuit if u=v. A path traverses the vertices along it. A path is simple if it contains no edge more than once. Sultan Almuhammadi ICS 254: Graphs and Trees
39
The length of the path the length of the path p
|p| = number of edges in p e.g. p = (a,b), (b,c), (c,d) |p| = 3 Sultan Almuhammadi ICS 254: Graphs and Trees
40
Connected Graphs An undirected graph is connected iff there is a path between every pair of distinct vertices in the graph. Sultan Almuhammadi ICS 254: Graphs and Trees
41
Directed Connectedness
A directed graph is strongly connected iff there is a directed path from a to b for any two vertices a and b. It is weakly connected iff the underlying undirected graph (i.e., with edge directions removed) is connected. Note strongly implies weakly but not vice-versa. Sultan Almuhammadi ICS 254: Graphs and Trees
42
§10.5: Euler & Hamilton Paths
E.g. Can we walk through the town below, crossing each bridge exactly once, and return to start? A D B C Sultan Almuhammadi ICS 254: Graphs and Trees
43
§10.5: Euler & Hamilton Paths
Euler circuit: a simple circuit containing every edge (exactly once) Euler path: in G is a simple path containing every edge (exactly once) Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 43
44
The Euler Circuit/Path
Can we walk through the town below, crossing each bridge exactly once? (and return to start?) A D B C Dual multigraph The original problem Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 44
45
The Euler Circuit/Path
Exer: Does K4 have an EC? EP? Does K5 have an EC? EP? Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 45
46
Euler Path Theorems Thrm 1: A connected multigraph has an Euler circuit iff each vertex has even degree. Thrm 2: A connected multigraph has an Euler path (but not an Euler circuit) iff it has exactly 2 vertices of odd degree. One is the start, the other is the end. Sultan Almuhammadi ICS 254: Graphs and Trees
47
§10.5: Euler & Hamilton Paths
A Hamilton circuit is a circuit that traverses each vertex in G exactly once. A Hamilton path is a path that traverses each vertex in G exactly once. E.g. Does W5 have an HC? HP? Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 47
48
§10.7: Planar Graphs Defn. G is plannar if it can be drawn on the plane without crossing edges. Eg. K3, K4, Q2 Exer: Is K3,3 plannar? Exer: Is K5 plannar? Sultan Almuhammadi ICS 254: Graphs and Trees
49
§10.8: Graph Coloring Coloring of a simple graph G=(V,E) is a mapping f:VA, where A = {1, 2,..,n} is a set of colors, such that for every edge (x,y) in E, f(x) ≠ f(y) i.e. Adjacent vertices have different colors G: Sultan Almuhammadi ICS 254: Graphs and Trees
50
§10.8: Graph Coloring The chromatic number of G, denoted by χ(G), is the minimum number of colors G can have. E.g. Find χ(G). G: Sultan Almuhammadi ICS 254: Graphs and Trees
51
Graph Coloring Example
E.g. Find χ(W5) Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 51
52
Exer: Graph Coloring Exer: Find χ(G) where G is: W8 K5 K5,3
Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 52
53
Graph Coloring Theorems on χ(G): If G is bipartite, then χ(G) ≤ 2
If G is a plannar graph, then χ(G) ≤ 4 (Map coloring of the dual graph*) Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 53
54
§11.1: Introduction to Trees
A tree is a connected undirected graph that contains no circuits. Thrm1: There is a unique simple path between any two of its nodes. Thrm2: T=(V,E) is a tree iff |E| = |V| - 1 A (not-necessarily-connected) undirected graph without simple circuits is called a forest. A forest is a bunch of trees Sultan Almuhammadi ICS 254: Graphs and Trees
55
Tree and Forest Examples
Leaves in green, internal nodes in brown. A Tree: A Forest: Sultan Almuhammadi ICS 254: Graphs and Trees
56
Rooted Trees A rooted tree is a tree in which one node has been designated the root. Every edge is directed away from the root. Keywords about rooted trees: Parent, child, siblings, ancestors, descendents, leaf, internal node, subtree. Sultan Almuhammadi ICS 254: Graphs and Trees
57
Same tree except for choice of root
Rooted Tree Examples Note that a given unrooted tree with n nodes yields n different rooted trees. Same tree except for choice of root root root Sultan Almuhammadi ICS 254: Graphs and Trees
58
Rooted-Tree Terminology Exercise
Find the parent, children, siblings, ancestors, & descendants of node f. o n h r d m b root a c g e q i f l p j k Sultan Almuhammadi ICS 254: Graphs and Trees
59
n-ary trees A rooted tree is called n-ary if every vertex has no more than n children. e.g. binary tree for n = 2 Sultan Almuhammadi ICS 254: Graphs and Trees
60
Rooted-Tree Terminology
Definition: The level of a node is the length of the simple path from the root to the node. The height of a tree is maximum node level. Sultan Almuhammadi ICS 254: Graphs and Trees
61
§11.3: Tree Traversal Preorder traversal Inorder traversal
Root, then subtrees (left-to-right) Inorder traversal Left subtree, root, then other subtrees Postorder traversal Subtrees (left-to-right) before the root. Sultan Almuhammadi ICS 254: Graphs and Trees
62
Infix/prefix/postfix notation
E.g. Draw the rooted tree for: (x + y) / (x^2) Infix form: (x+y) / (x^2) (need parentheses) Prefix form (polish notation): /+xy^x2 Postfix form (reverse polish notation): xy+x2^/ Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 62
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.