Graph & Trees Chapters 10-11

Slides:



Advertisements
Similar presentations
Chapter 9 Graphs.
Advertisements

22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Graph Theory in CS Route Search in Online Map Services
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE Discrete.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Let us switch to a new topic:
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
GRAPH Learning Outcomes Students should be able to:
Graphs Chapter 10.
Graph Theory 4/23/2017.
16.1 CompSci 102© Michael Frank Today’s topics GraphsGraphs –Basics & types –Properties –Connectivity –Hamilton & Euler Paths Reading: Sections Reading:
Module #19: Graph Theory: part I Rosen 5 th ed., chs. 8-9 내년 3 월 ? 교환 학생 프로그램 영어 점수 미리미리 준비하세요.
1 Elements of Graph Theory Quick review of Chapters 9.1… 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
1 CS104 : Discrete Structures Chapter V Graph Theory.
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
Graphs What are Graphs? General meaning in everyday math: A plot or chart of numerical data using a coordinate system. Technical meaning in discrete.
Discrete Structures Trees (Ch. 11)
1 12/2/2015 MATH 224 – Discrete Mathematics Formally a graph is just a collection of unordered or ordered pairs, where for example, if {a,b} G if a, b.
September1999 CMSC 203 / 0201 Fall 2002 Week #13 – 18/20/22 November 2002 Prof. Marie desJardins.
Graph Theory and Applications
Graphs Basic properties.
Graph Theory Unit: 4.
LOGO.  Relations:  In these slides: Introductions to graphs Graph terminology Representing graphs and graph isomorphism Connectivity Euler and Hamilton.
Chapter 9: Graphs.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
Chap 7 Graph Def 1: Simple graph G=(V,E) V : nonempty set of vertices E : set of unordered pairs of distinct elements of V called edges Def 2: Multigraph.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
GRAPH THEORY Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
An Introduction to Graph Theory
Applied Discrete Mathematics Week 14: Trees
Graphs: Definitions and Basic Properties
Chapter 9 (Part 2): Graphs
Let us switch to a new topic:
Lecture 5.2: Special Graphs and Matrix Representation
Lecture 19: CONNECTIVITY Sections
Applied Discrete Mathematics Week 13: Graphs
Special Graphs By: Sandeep Tuli Astt. Prof. CSE.
Copyright © Zeph Grunschlag,
Graph Graphs and graph theory can be used to model:
Graphs Hubert Chan (Chapter 9) [O1 Abstract Concepts]
Trees Chapter 11.
COT 3100, Spring 2001 Applications of Discrete Structures
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
Graph theory Definitions Trees, cycles, directed graphs.
Agenda Lecture Content: Introduction to Graph Path and Cycle
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Graphs Slides are adopted from “Discrete.
Discrete Mathematics and its Applications
Advanced Algorithms Analysis and Design
Discrete Mathematics and its Applications
Graphs Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Graphs.
Graphs.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Based on slides by Y. Peng University of Maryland
Chapter 13 (Part 1): Graphs
Rosen 5th ed., chs. 8-9 ~44 slides (more later), ~3 lectures
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
Discrete Mathematics and its Applications
CS100: Discrete structures
Discrete Mathematics and its Applications
Rosen 5th ed., ch. 8.1~8.5 ~44 slides (more later), ~3 lectures
Let us switch to a new topic:
Lecture 10: Graphs Graph Terminology Special Types of Graphs
Applied Discrete Mathematics Week 13: Graphs
Based on slides by Y. Peng University of Maryland
Presentation transcript:

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

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

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

§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

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

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

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

Pseudographs Like a multigraph, but edges connecting a node to itself are allowed. (R may be reflexive.) A pseudograph G=(V, E) where Edge eE 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

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

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

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

§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

Adjacency Let 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

Degree of a Vertex Let 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

Exercise Find: An element of degree 4 An element of degree 3 A pendant An isolated vertix Sultan Almuhammadi ICS 254: Graphs and Trees

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

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

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

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

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

Complete Graphs For any nN, 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,vV: uv{u,v}E. K1 K4 K2 K3 K5 K6 Note that Kn has edges. Sultan Almuhammadi ICS 254: Graphs and Trees

How many edges are there in Cn? Cycles For any n3, a cycle on n vertices, Cn, is a simple graph where V={v1,v2,… ,vn} and E={{v1,v2},{v2,v3},…,{vn1,vn},{vn,v1}}. C3 C4 C5 C6 C8 C7 How many edges are there in Cn? Sultan Almuhammadi ICS 254: Graphs and Trees

How many edges are there in Wn? 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},…,{vhub,vn}}. W3 W4 W5 W6 W8 W7 How many edges are there in Wn? Sultan Almuhammadi ICS 254: Graphs and Trees

Number of vertices: 2n. Number of edges:Exercise to try! n-cubes (hypercubes) For any nN, 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

Bipartite Graphs 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 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

Bipartite Graphs Exer: Are these graphs bipartite? G H Sultan Almuhammadi ICS 254: Graphs and Trees

Complete Bipartite Graphs For m,nN, the complete bipartite graph Km,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. K4,3 Km,n has _____ nodes and _____ edges. Sultan Almuhammadi ICS 254: Graphs and Trees

Subgraphs A 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

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

§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

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

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

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

Graph Isomorphism Formal definition: Simple graphs G1=(V1, E1) 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

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

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

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

§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

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

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

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

§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

§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

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

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

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

§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

§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

§10.8: Graph Coloring Coloring 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

§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

Graph Coloring Example E.g. Find χ(W5) Sultan Almuhammadi 12/4/2018 ICS 254: Graphs and Trees ICS 254: Graphs and Trees 51

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

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

§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

Tree and Forest Examples Leaves in green, internal nodes in brown. A Tree: A Forest: Sultan Almuhammadi ICS 254: Graphs and Trees

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

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

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

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

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

§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

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