/
Sultan  Almuhammadi ICS 254: Graphs and Trees  1 Graph & Trees Sultan  Almuhammadi ICS 254: Graphs and Trees  1 Graph & Trees

Sultan Almuhammadi ICS 254: Graphs and Trees 1 Graph & Trees - PowerPoint Presentation

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
344 views
Uploaded On 2019-11-04

Sultan Almuhammadi ICS 254: Graphs and Trees 1 Graph & Trees - PPT Presentation

Sultan Almuhammadi ICS 254 Graphs and Trees 1 Graph amp Trees Chapters 1011 Acknowledgement This is a modified version of Module22 on Graph Theory by Michael Frank Sultan Almuhammadi ICS 254 Graphs and Trees ID: 763037

254 graphs ics trees graphs 254 trees ics sultan almuhammadi graph edges vertices simple degree directed path node tree

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Sultan Almuhammadi ICS 254: Graphs and ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Sultan Almuhammadi ICS 254: Graphs and Trees 1 Graph & TreesChapters 10-11 Acknowledgement This is a modified version of Module#22 on Graph Theory by Michael Frank

Sultan Almuhammadi ICS 254: Graphs and Trees 2 What are Graphs?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. Not

Sultan Almuhammadi ICS 254: Graphs and Trees 3 Applications of GraphsPotentially 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 GraphA graph G = (V, E)V is a nonempty set of verticiesE 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 Simple GraphsA 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 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}}Example of a Simple Graph

Sultan Almuhammadi ICS 254: Graphs and Trees 7 MultigraphsLike 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 PseudographsLike a multigraph, but edges connecting a node to itself are allowed. (R may be reflexive.) A pseudograph G =( V , E) whereEdge eE is a loop if e = {u, u} = {u} .E.g., nodes are the cities in a state, edges arethe roads serving/connectingthe cities. loops

Sultan Almuhammadi ICS 254: Graphs and Trees 9 Directed GraphsCorrespond 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 MultigraphsLike 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: SummarySummary 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 TerminologyYou 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 AdjacencyLet G be an undirected graph with edge set E. Let e  E 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 VertexLet G be an undirected graph, v V 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 ExerciseFind:An element of degree 4An element of degree 3A pendantAn isolated vertix

Sultan Almuhammadi ICS 254: Graphs and Trees 16 Handshaking TheoremLet 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 AdjacencyLet 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 ue comes from u, e goes to v.e connects u to v, e goes from u to vthe initial vertex of e is uthe terminal vertex of e is v

Sultan Almuhammadi ICS 254: Graphs and Trees 18 Directed DegreeLet 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 TheoremLet 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 StructuresSpecial cases of undirected graph structures:Complete graphs Kn Cycles C n Wheels W n n-Cubes QnBipartite graphsComplete bipartite graphs Km,n

Sultan Almuhammadi ICS 254: Graphs and Trees 21 Complete GraphsFor any nN , a complete graph on n vertices, K n, is a simple graph with n nodes in which every node is adjacent to every other node: u,vV: uv{u,v}E. K 1 K 2 K 3 K 4 K 5 K 6 Note that K n has edges.

Sultan Almuhammadi ICS 254: Graphs and Trees 22 CyclesFor any n3, a cycle on n vertices, C n , is a simple graph where V ={v1,v2,… ,vn} and E={{v1,v2},{v2,v3},…,{vn 1,vn},{vn,v1}}. C 3 C 4 C 5 C 6 C 7 C 8 How many edges are there in C n ?

Sultan Almuhammadi ICS 254: Graphs and Trees 23 Wheels For any n 3 , 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},…,{v hub,vn}}. W 3 W 4 W 5 W 6 W 7 W 8 How many edges are there in W n ?

Sultan Almuhammadi ICS 254: Graphs and Trees 24 n-cubes (hypercubes)For any n N , the hypercube Q n is a simple graph consisting of two copies of Q n -1 connected together at corresponding nodes. Q0 has 1 node. Q 0 Q 1 Q 2 Q 3 Q 4 Number of vertices: 2 n . Number of edges:Exercise to try!

Sultan Almuhammadi ICS 254: Graphs and Trees 25 Def’n.: A graph G=(V,E ) is bipartite (two-part) iff V = V1  V2 where V1 ∩ V2= and eE: v1V1,v2V2 : e={v1,v2}.In English: The graph can be divided into two partsin such a way that all edges go between the two parts. Bipartite Graphs V 1 V 2 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 Exer: Are these graphs bipartite?Bipartite Graphs G H

Sultan Almuhammadi ICS 254: Graphs and Trees 27 Complete Bipartite GraphsFor m,n  N , the complete bipartite graph K m,n is a bipartite graph where |V1| = m, |V2| = n, and E = {{v1,v2}|v1V1  v2V2}.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. K 4,3 K m , n has _____ nodes and _____ edges.

Sultan Almuhammadi ICS 254: Graphs and Trees 28 SubgraphsA subgraph of a graph G=(V , E ) is a graph H =( W,F) where WV and FE. G H

Sultan Almuhammadi ICS 254: Graphs and Trees 29 Graph UnionsThe union G1  G 2 of two simple graphs G 1 =(V1, E1) and G2=(V2,E2) is the simple graph (V1V2, E 1E2). a b c d e a b c d f 

Sultan Almuhammadi ICS 254: Graphs and Trees 30 §10.3: Graph Representations & IsomorphismGraph representations: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 ListsA table with 1 row per vertex, listing its adjacent vertices. a b d c f e

Sultan Almuhammadi ICS 254: Graphs and Trees 32 Directed Adjacency Lists1 row per node, listing the terminal nodes of each edge incident from that node.

Sultan Almuhammadi ICS 254: Graphs and Trees 33 Adjacency MatricesA way to represent simple graphspossibly with self-loops.Matrix A=[ a ij ] , where a ij 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 IsomorphismFormal definition:Simple graphs G1 =( V 1 , E 1 ) and G2=(V2, E2) are isomorphic iff  a bijection f:V1V2 such that  a,bV1, 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 IsomorphismNecessary but not sufficient conditions for G 1 =( V 1 , E 1) 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 ExampleIf isomorphic, label the 2nd graph to show the isomorphism, else identify difference. a b c d e f b d a e f c

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. a b c d e Same # of vertices Same # of edges Different # of vertices of degree 2 (1 vs 3)

Sultan Almuhammadi ICS 254: Graphs and Trees 38 §10.4: ConnectivityA 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 paththe length of the path p |p| = number of edges in pe.g. p = (a,b), (b,c), (c,d) |p| = 3

Sultan Almuhammadi ICS 254: Graphs and Trees 40 Connected GraphsAn 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 ConnectednessA 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 PathsE.g. Can we walk through the town below, crossing each bridge exactly once, and return to start? A B C D

12/13/2015 ICS 254: Graphs and Trees 43 §10.5: Euler & Hamilton Paths E uler circuit: a simple circuit containing every e dge (exactly once) E uler path: in G is a simple path containing every edge (exactly once)Sultan Almuhammadi ICS 254: Graphs and Trees43

12/13/2015 ICS 254: Graphs and Trees 44 The Euler Circuit/Path Can we walk through the town below, crossing each bridge exactly once? (and return to start?) A B C D The original problem Dual multigraph Sultan Almuhammadi ICS 254: Graphs and Trees 44

12/13/2015 ICS 254: Graphs and Trees 45 The Euler Circuit/Path Exer : Does K 4 have an EC? EP? Does K 5 have an EC? EP? Sultan AlmuhammadiICS 254: Graphs and Trees45

Sultan Almuhammadi ICS 254: Graphs and Trees 46 Euler Path TheoremsThrm 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.

12/13/2015 ICS 254: Graphs and Trees 47 §10.5: Euler & Hamilton Paths A Hamil t on circuit is a circuit that traverses each ver t ex 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 AlmuhammadiICS 254: Graphs and Trees47

Sultan Almuhammadi ICS 254: Graphs and Trees 48 §10.7: Planar GraphsDefn. G is plannar if it can be drawn on the plane without crossing edges. Eg . K 3 , K 4 , Q 2Exer: Is K3,3 plannar?Exer: Is K5 plannar?

Sultan Almuhammadi ICS 254: Graphs and Trees 49 §10.8: Graph ColoringColoring of a simple graph G=(V,E) is a mapping f:V A, 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 ColoringThe chromatic number of G, denoted by χ (G), is the minimum number of colors G can have . E.g. Find χ(G). G:

12/13/2015 ICS 254: Graphs and Trees 51 Graph Coloring Example E.g. Find χ ( W 5 )Sultan Almuhammadi ICS 254: Graphs and Trees51

12/13/2015 ICS 254: Graphs and Trees 52 Exer: Graph Coloring Exer : Find χ (G) where G is: W 8K5K 5,3Sultan AlmuhammadiICS 254: Graphs and Trees52

12/13/2015 ICS 254: Graphs and Trees 53 Graph Coloring Theorems on χ (G ) : If G is bipartite, then χ(G) ≤ 2If G is a plannar graph, then χ(G) ≤ 4 (Map coloring of the dual graph*)Sultan AlmuhammadiICS 254: Graphs and Trees53

Sultan Almuhammadi ICS 254: Graphs and Trees 54 §11.1: Introduction to TreesA 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 ExamplesA Tree:A Forest: Leaves in green, internal nodes in brown.

Sultan Almuhammadi ICS 254: Graphs and Trees 56 Rooted TreesA 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 Rooted Tree ExamplesNote that a given unrooted tree with n nodes yields n different rooted trees. root root Same tree except for choice of root

Sultan Almuhammadi ICS 254: Graphs and Trees 58 Rooted-Tree Terminology ExerciseFind the parent,children, siblings,ancestors, & descendants of node f. a b c d e f g h i j k l m n o p q r root

Sultan Almuhammadi ICS 254: Graphs and Trees 59 n-ary treesA 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 TerminologyDefinition: 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 TraversalPreorder traversalRoot, then subtrees (left-to-right)Inorder traversal Left subtree, root, then other subtrees Postorder traversal Subtrees (left-to-right) before the root.

12/13/2015 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^x2Postfix form (reverse polish notation): xy+x2^/Sultan AlmuhammadiICS 254: Graphs and Trees62