Algorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95

Similar documents
Algorithms. Graphs. Algorithms

Introduction III. Graphs. Motivations I. Introduction IV

Elements of Graph Theory

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

INTRODUCTION TO GRAPH THEORY. 1. Definitions

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

CS 311 Discrete Math for Computer Science Dr. William C. Bulko. Graphs

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

Graphs. Pseudograph: multiple edges and loops allowed

Varying Applications (examples)

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Graphs. Introduction To Graphs: Exercises. Definitions:

Discrete mathematics II. - Graphs

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

Section 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.

CMSC 380. Graph Terminology and Representation

Assignments are handed in on Tuesdays in even weeks. Deadlines are:

Paths. Path is a sequence of edges that begins at a vertex of a graph and travels from vertex to vertex along edges of the graph.

Assignment 4 Solutions of graph problems

Math 776 Graph Theory Lecture Note 1 Basic concepts

Graph and Digraph Glossary

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Introduction to Graph Theory

Copyright 2000, Kevin Wayne 1

Graph (1A) Young Won Lim 4/19/18

Chapter 3: Paths and Cycles

Discrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours)

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

Section 3.4 Basic Results of Graph Theory

Graph Theory. Part of Texas Counties.

Chapter 11: Graphs and Trees. March 23, 2008

Majority and Friendship Paradoxes

11.4 Bipartite Multigraphs

Ma/CS 6b Class 9: Euler s Formula

Basics of Graph Theory

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

Paths, Circuits, and Connected Graphs

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

Jordan Curves. A curve is a subset of IR 2 of the form

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/z

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

1. a graph G = (V (G), E(G)) consists of a set V (G) of vertices, and a set E(G) of edges (edges are pairs of elements of V (G))

Lecture 4: Bipartite graphs and planarity

Induction Review. Graphs. EECS 310: Discrete Math Lecture 5 Graph Theory, Matching. Common Graphs. a set of edges or collection of two-elt subsets

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Jordan Curves. A curve is a subset of IR 2 of the form

Graph Overview (1A) Young Won Lim 5/9/18

Graph Theory Mini-course

CS 2336 Discrete Mathematics

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks

Hamilton paths & circuits. Gray codes. Hamilton Circuits. Planar Graphs. Hamilton circuits. 10 Nov 2015

Theorem 3.1 (Berge) A matching M in G is maximum if and only if there is no M- augmenting path.

Chapter 1 Graph Theory

Chapter 2 Graphs. 2.1 Definition of Graphs

Key Graph Theory Theorems

Computer Science 280 Fall 2002 Homework 10 Solutions

How can we lay cable at minimum cost to make every telephone reachable from every other? What is the fastest route between two given cities?

MAS 341: GRAPH THEORY 2016 EXAM SOLUTIONS

Mathematics and Statistics, Part A: Graph Theory Problem Sheet 1, lectures 1-4

Inf 496/596 Topics in Informatics: Analysis of Social Network Data

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

Graph Algorithms. Tours in Graphs. Graph Algorithms

Lecture 6: Graph Properties

UNDIRECTED GRAPH: a set of vertices and a set of undirected edges each of which is associated with a set of one or two of these vertices.

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

Module 2: NETWORKS AND DECISION MATHEMATICS

Fundamental Properties of Graphs

Discrete mathematics

Simple graph Complete graph K 7. Non- connected graph

Week 7 Convex Hulls in 3D

How many colors are needed to color a map?

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

MATH 350 GRAPH THEORY & COMBINATORICS. Contents

Chapter 9 Graph Algorithms

K 4 C 5. Figure 4.5: Some well known family of graphs

Outline. 1 The matching problem. 2 The Chinese Postman Problem

Combinatorics: The Fine Art of Counting

ECS 20 Lecture 17b = Discussion D8 Fall Nov 2013 Phil Rogaway

Computational Discrete Mathematics

Lecture 3: Graphs and flows

Approximation slides 1. An optimal polynomial algorithm for the Vertex Cover and matching in Bipartite graphs

Worksheet for the Final Exam - Part I. Graphs

22 Elementary Graph Algorithms. There are two standard ways to represent a

Chapter 9 Graph Algorithms

Graph Theory II. Po-Shen Loh. June edges each. Solution: Spread the n vertices around a circle. Take parallel classes.

Part II. Graph Theory. Year

Transcription:

Algorithms: Graphs Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Graphs Spring 2012 1 / 95

Graphs Definition: A graph is a collection of edges and vertices. Each edge connects two vertices. Amotz Bar-Noy (CUNY) Graphs Spring 2012 2 / 95

Graphs Vertices: Nodes, points, computers, users, items,... Edges: Arcs, links, lines, cables,... Applications: Communication, Transportation, Databases, Electronic Circuits,... An alternative definition: A graph is a collection of subsets of size 2 from the set {1,..., n}. A hyper-graph is a collection of subsets of any size from the set {1,..., n}. Amotz Bar-Noy (CUNY) Graphs Spring 2012 3 / 95

Drawing Graphs Four possible drawings illustrating the same graph: Amotz Bar-Noy (CUNY) Graphs Spring 2012 4 / 95

Drawing Graphs Two drawings representing the same graph: Amotz Bar-Noy (CUNY) Graphs Spring 2012 5 / 95

Graph Isomorphism Graph G 1 and graph G 2 are isomorphic if there is a one-one correspondence between their vertices such that the number of edges joining any two vertices of G 1 is equal to the number of edges joining the corresponding vertices of G 2. A D a d B E f b C F c e a A b B c C d D e E f F Amotz Bar-Noy (CUNY) Graphs Spring 2012 6 / 95

The Bridges of Königsberg A C D B Is it possible to traverse each of the 7 bridges of this town exactly once, starting and ending at any point? Amotz Bar-Noy (CUNY) Graphs Spring 2012 7 / 95

The Bridges of Königsberg A C D B Is it possible to traverse each of the edges of this graph exactly once, starting and ending at any vertex? Does a graph have an Euler tour? Amotz Bar-Noy (CUNY) Graphs Spring 2012 8 / 95

The Four Coloring Problem A E B D F C Is it possible to color a map with at most 4 colors such that neighboring countries get different colors? Amotz Bar-Noy (CUNY) Graphs Spring 2012 9 / 95

The Four Coloring Problem A B F E C D Is it possible to color the vertices of this graph with at most 4 colors? Is it possible to color every planar graph with at most 4 colors? Amotz Bar-Noy (CUNY) Graphs Spring 2012 10 / 95

The Three Utilities Problem Water A Electricity B Telephone C Is it possible to connect the houses {A, B, C} with the utilities {Water, Electricity,Telephone} such that cables do not cross? Amotz Bar-Noy (CUNY) Graphs Spring 2012 11 / 95

The Three Utilities Problem Water A Electricity B Telephone C Is it possible to draw the vertices and edges of this graph such that edges do not cross? Which graphs are planar? Amotz Bar-Noy (CUNY) Graphs Spring 2012 12 / 95

The Marriage Problem Anna loves: Betsy loves: Claudia loves: Donna loves: Elizabeth loves: Bob and Charlie Charlie and David David and Edward Edward and Albert Albert and Bob Under what conditions a collection of girls, each loves several boys, can be married so that each girl marries a boy she loves? Amotz Bar-Noy (CUNY) Graphs Spring 2012 13 / 95

The Marriage Problem A B C D E a b c d e Find in this graph a set of disjoint edges that cover all the vertices in the top side. Does a (bipartite) graph have a perfect matching? Amotz Bar-Noy (CUNY) Graphs Spring 2012 14 / 95

The Travelling Salesperson Problem B A 3 4 6 5 5 C 3 E 4 6 3 D 2 A salesperson wants to sell products in the above 5 cities {A, B, C, D, E} starting at A and ending at A while travelling as little as possible. Amotz Bar-Noy (CUNY) Graphs Spring 2012 15 / 95

The Travelling Salesperson Problem B A 3 4 6 5 5 C 3 E 4 6 3 D 2 Find the shortest path in this graph that visits each vertex at least once and starts and ends at vertex A. Find the shortest Hamiltonian cycle in a graph. Amotz Bar-Noy (CUNY) Graphs Spring 2012 16 / 95

The Activity Center Problem A B C D E What is the maximal number of activities that can be served by a single server? Amotz Bar-Noy (CUNY) Graphs Spring 2012 17 / 95

The Activity Center Problem B E A D C What is the maximal number of vertices in this graph with no edge between any two of them? Find a maximum independent set in a graph. Amotz Bar-Noy (CUNY) Graphs Spring 2012 18 / 95

Chemical Molecules H H H H H C H H C C C H H H H H Methane Propane In the C x H y molecule, y hydrogen atoms are connected to x carbon atoms. A hydrogen atom can be connected to exactly one carbon atom. A carbon atom can be connected to four other atoms either hydrogen or carbon. Amotz Bar-Noy (CUNY) Graphs Spring 2012 19 / 95

Chemical Molecules How many possible structures exist for the molecule C 4 H 10? How many non-isomorphic connected graphs exist with x vertices of degree 4 and y vertices of degree 1? Is there a (connected) graph whose degree sequence is d 1 d n? How many non-isomorphic such graphs exist? Amotz Bar-Noy (CUNY) Graphs Spring 2012 20 / 95

Some Notations G = (V, E) - a graph G. V = {1,..., n} - a set of vertices. E V V - a set of edges. e = (u, v) E - an edge. V = V = n - number of vertices. E = E = m - number of edges. Amotz Bar-Noy (CUNY) Graphs Spring 2012 21 / 95

Directed and Undirected Graphs In undirected graphs: (u, v) = (v, u). In directed graphs (D-graphs): (u v) (v u). The underlying undirected graph G = (V, E ) of a directed graph G = (V, E): Has the same set of vertices: V = V. Has all the edges of G without their direction: (u v) becomes (u, v). Amotz Bar-Noy (CUNY) Graphs Spring 2012 22 / 95

Undirected Edges Vertices u and v are the endpoints of the edge (u, v). Edge (u, v) is incident with vertices u and v. Vertices u and v are neighbors if edge (u, v) exists. u is adjacent to v and v is adjacent to u. Vertex u has degree d if it has d neighbors. Edge (v, v) is a (self) loop edge. Edges e 1 = (u, v) and e 2 = (u, v) are parallel edges. Amotz Bar-Noy (CUNY) Graphs Spring 2012 23 / 95

Directed Edges Vertex u is the origin (initial) and vertex v is the destination (terminal) of the directed edge (u v). Vertex v is the neighbor of vertex u if the directed edge (u v) exists. v is adjacent to u (but u is not adjacent to v). Vertex u has out-degree d if it has d neighbors. in-degree d if it is the neighbor of d vertices. Amotz Bar-Noy (CUNY) Graphs Spring 2012 24 / 95

Weighted Graphs In Weighted graphs there exists a weight function: w : E R. w : weight, distance, length, time, cost, capacity,... Weights could be negative. Amotz Bar-Noy (CUNY) Graphs Spring 2012 25 / 95

Weighted Graphs In Weighted graphs there exists a weight function: w : E R. w : weight, distance, length, time, cost, capacity,... Weights could be negative. B A C w(ac) w(ab) + w(bc) Sometimes weights obey the triangle inequality. E.g., Distances in the plane. Amotz Bar-Noy (CUNY) Graphs Spring 2012 25 / 95

Simple Graphs A simple directed or undirected graph is a graph with no parallel edges and no self loops. In a simple directed graph both edges: (u v) and (v u) could exist (they are not parallel edges). Amotz Bar-Noy (CUNY) Graphs Spring 2012 26 / 95

Simple Graphs A simple directed or undirected graph is a graph with no parallel edges and no self loops. In a simple directed graph both edges: (u v) and (v u) could exist (they are not parallel edges). Number of Edges in Simple Graphs: A simple undirected graph has at most m = ( n 2) edges. A simple directed graph has at most m = n(n 1) edges. A dense simple (directed or undirected) graph has many edges: m = Θ(n 2 ). A sparse (shallow) simple (directed or undirected) graph has few edges: m = Θ(n). Amotz Bar-Noy (CUNY) Graphs Spring 2012 26 / 95

Labelled and Unlabelled Graphs In a labelled graph each vertex has a unique label (ID). Usually the labels are: 1,..., n. Amotz Bar-Noy (CUNY) Graphs Spring 2012 27 / 95

Labelled and Unlabelled Graphs In a labelled graph each vertex has a unique label (ID). Usually the labels are: 1,..., n. Observation: There are 2 (n 2) non-isomorphic labelled graphs with n vertices. Proof: Each possible edge exists or does not exist. Amotz Bar-Noy (CUNY) Graphs Spring 2012 27 / 95

Labelled Graphs 1 1 1 1 2 3 2 3 2 3 2 3 1 1 1 1 2 3 2 3 2 3 2 3 The 8 labelled graphs with n = 3 vertices. Amotz Bar-Noy (CUNY) Graphs Spring 2012 28 / 95

Unlabelled Graphs The 4 unlabelled graph with n = 3 vertices. Amotz Bar-Noy (CUNY) Graphs Spring 2012 29 / 95

Paths and Cycles An undirected or directed path P = v 0, v 1,..., v k of length k is an ordered list of vertices such that (v i, v i+1 ) or (v i v i+1 ) exists for 0 i k 1 and all the edges are different. An undirected or directed cycle C = v 0, v 1,..., v k 1, v 0 of length k is an undirected or directed path that starts and ends with the same vertex. In a simple path, directed or undirected, all the vertices are different. In a simple cycle, directed or undirected, all the vertices except v 0 = v k are different. Amotz Bar-Noy (CUNY) Graphs Spring 2012 30 / 95

Special Paths and Cycles An undirected or directed Euler path (tour) is a path that traverses all the edges. An undirected or directed Euler cycle (circuit) is a cycle that traverses all the edges. An undirected or directed Hamiltonian path (tour) is a simple path that visits all the vertices. An undirected or directed Hamiltonian cycle (circuit) is a simple cycle that visits all the vertices. Amotz Bar-Noy (CUNY) Graphs Spring 2012 31 / 95

Connected Graphs and Strongly Connected Directed Graphs Connectivity: In connected undirected graphs there exists a path between any pair of vertices. Observation: In a simple connected undirected graph there are at least m = n 1 edges. Strong connectivity: In a strongly connected directed graph there exists a directed path from u to v for any pair of vertices u and v. Observation: In a simple strongly connected directed graph there are at least m = n edges. Amotz Bar-Noy (CUNY) Graphs Spring 2012 32 / 95

Weakly Connected Directed Graphs Definition I: In a weakly connected directed graph there exists a directed path either from u to v or from v to u for any pair of vertices u and v. Definition II: In a weakly connected directed graph there exists a path between any pair of vertices in the underlying undirected graph. Observation: The definitions are not equivalent: Def. I implies Def. II but Def. II does not imply Def. I. Amotz Bar-Noy (CUNY) Graphs Spring 2012 33 / 95

Sub-Graphs A (directed or undirected) Graph G = (V, E ) is a sub-graph of a (directed or undirected) graph G = (V, E) if: V V and E E. G G G G G, G, G are sub-graphs of G Amotz Bar-Noy (CUNY) Graphs Spring 2012 34 / 95

Connected Components - Undirected Graphs A connected sub-graph G is a connected component of an undirected graph G if there is no connected sub-graph G of G such that G is also a subgraph of G. A connected component G is a maximal sub-graph with the connectivity property. A connected graph has exactly one connected component. Amotz Bar-Noy (CUNY) Graphs Spring 2012 35 / 95

Connected Components - Directed Graphs A strongly connected directed sub-graph G is a strongly connected component of a directed graph G if there is no strongly connected directed sub-graph G of G such that G is also a subgraph of G. A strongly connected component G is a maximal sub-graph with the strong connectivity property. A strongly connected graph has exactly one strongly connected component. Amotz Bar-Noy (CUNY) Graphs Spring 2012 36 / 95

Counting Edges Theorem: Let G be a simple undirected graph with n vertices and k connected components then: (n k)(n k + 1) n k m. 2 Corollary: A simple undirected graph with n vertices is connected if it has m edges for: (n 1)(n 2) m > 2 Amotz Bar-Noy (CUNY) Graphs Spring 2012 37 / 95

Assumptions Unless stated otherwise, usually a graph is: Simple. Undirected. Connected. Unweighted. Unlabelled. Amotz Bar-Noy (CUNY) Graphs Spring 2012 38 / 95

Forests and Trees Forest: A graph with no cycles. Tree: A connected graph with no cycles. Amotz Bar-Noy (CUNY) Graphs Spring 2012 39 / 95

Forests and Trees Forest: A graph with no cycles. Tree: A connected graph with no cycles. By definition: A tree is a connected forest. Each connected component of a forest is a tree. Amotz Bar-Noy (CUNY) Graphs Spring 2012 39 / 95

Trees Theorem: An undirected and simple graph is a tree if: It is connected and has no cycles. It is connected and has exactly m = n 1 edges. It has no cycles and has exactly m = n 1 edges. It is connected and deleting any edge disconnects it. Any 2 vertices are connected by exactly one path. It has no cycles and any new edge forms one cycle. Amotz Bar-Noy (CUNY) Graphs Spring 2012 40 / 95

Trees Theorem: An undirected and simple graph is a tree if: It is connected and has no cycles. It is connected and has exactly m = n 1 edges. It has no cycles and has exactly m = n 1 edges. It is connected and deleting any edge disconnects it. Any 2 vertices are connected by exactly one path. It has no cycles and any new edge forms one cycle. Corollary: The number of edges in a forest with n vertices and k trees is m = n k. Amotz Bar-Noy (CUNY) Graphs Spring 2012 40 / 95

Rooted and Ordered Trees Rooted trees: One vertex is designated as the root. Vertices with degree 1 are called leaves. Non-leaves vertices are internal vertices. All the edges are directed from the root to the leaves. Amotz Bar-Noy (CUNY) Graphs Spring 2012 41 / 95

Rooted and Ordered Trees Rooted trees: One vertex is designated as the root. Vertices with degree 1 are called leaves. Non-leaves vertices are internal vertices. All the edges are directed from the root to the leaves. Ordered trees: Children of an internal parent vertex are ordered. Amotz Bar-Noy (CUNY) Graphs Spring 2012 41 / 95

Drawing Rooted Trees Parents above children. Older children to the left of younger children. Amotz Bar-Noy (CUNY) Graphs Spring 2012 42 / 95

Binary Trees Binary trees: The root has degree either 1 or 2, the leaves have degree 1, and the degree of non-root internal vertices is either 2 or 3. Amotz Bar-Noy (CUNY) Graphs Spring 2012 43 / 95

Star Trees Star: A rooted tree with 1 root and n 1 leaves. The degree of one vertex (the root) is n 1 and the degree of any non-root vertex is 1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 44 / 95

Path Trees Path: A tree with exactly 2 leaves. Claim I: The degree of a non-leave vertex is exactly 2. Claim II: The path is the only tree with exactly 2 leaves. Amotz Bar-Noy (CUNY) Graphs Spring 2012 45 / 95

Counting Labelled Trees 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 1 2 3 4 1 2 4 3 1 3 2 4 1 3 4 2 1 4 2 3 1 4 3 2 2 1 3 4 2 1 3 4 2 3 1 4 2 4 1 3 3 1 2 4 3 2 1 4 Theorem: There are n n 2 distinct labelled n vertices trees. Amotz Bar-Noy (CUNY) Graphs Spring 2012 46 / 95

Null Graphs Null graphs are graphs with no edges. The null graph with n vertices is denoted by N n. In null graphs m = 0. Amotz Bar-Noy (CUNY) Graphs Spring 2012 47 / 95

Complete Graphs Complete graphs (cliques) are graphs with all possible edges. The complete graph with n vertices is denoted by K n. In complete graphs m = ( ) n 2 = n(n 1) 2. Amotz Bar-Noy (CUNY) Graphs Spring 2012 48 / 95

Cycles Cycles (rings) are connected graphs in which all vertices have degree 2 (n 3). The cycle with n vertices is denoted by C n. In cycles m = n. Amotz Bar-Noy (CUNY) Graphs Spring 2012 49 / 95

Paths Paths are cycles with one edge removed. The path with n vertices is denoted by P n. In paths m = n 1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 50 / 95

Stars Stars are graphs with one root and n 1 leaves. The star with n vertices is denoted by S n. In stars m = n 1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 51 / 95

Wheels Wheels are stars in which all the n 1 leaves form a cycle C n 1 (n 4). The wheel with n vertices is denoted by W n. In wheels m = 2n 2. Amotz Bar-Noy (CUNY) Graphs Spring 2012 52 / 95

Bipartite Graphs A: B: Bipartite graphs V = A B: each edge is incident to one vertex from A and one vertex from B. Observation: A graph is bipartite iff each cycle is of even length. Amotz Bar-Noy (CUNY) Graphs Spring 2012 53 / 95

Complete Bipartite Graphs Complete bipartite graphs K r,c : All possible r c edges exist. Amotz Bar-Noy (CUNY) Graphs Spring 2012 54 / 95

Cubes 011 111 010 110 001 101 000 100 There are n = 2 k vertices representing all the 2 k binary sequences of length k. Two vertices are connected by an edge if their corresponding sequences differ by exactly one bit. Amotz Bar-Noy (CUNY) Graphs Spring 2012 55 / 95

Cubes Observation: Cubes are bipartite graphs. Proof: A: The vertices with even number of 1 in their binary representation. B The vertices with odd number of 1 in their binary representation. Any edge connects 2 vertices one from the set A and one from the set B. Amotz Bar-Noy (CUNY) Graphs Spring 2012 56 / 95

d-regular Graphs In d-regular graphs, the degree of each vertex is exactly d. In d-regular graphs, m = d n 2. The Petersen Graph: a 3-regular graph. Amotz Bar-Noy (CUNY) Graphs Spring 2012 57 / 95

Planar Graphs Definition: Planar graphs are graphs that can be drawn on the plane such that edges do not cross each other. Theorem: A graph is planar iff it does not have sub-graphs homeomorphic to K 5 and K 3,3. Theorem: Every planar graph can be drawn with straight lines. Amotz Bar-Noy (CUNY) Graphs Spring 2012 58 / 95

Non-Planar Graphs K 5 : the complete graph with 5 vertices. K 3,3 : the complete 3, 3 bipartite graph. Amotz Bar-Noy (CUNY) Graphs Spring 2012 59 / 95

Platonic Graphs Graphs that are formed from the vertices and edges of the five regular (Platonic) solids: Tetrahedron: 4 vertices 3-regular graph. Octahedron: 6 vertices 4-regular graph. Cube: 8 vertices 3-regular graph. Icosahedron: 12 vertices 5-regular graph. Dodecahedron: 20 vertices 3-regular graph. Amotz Bar-Noy (CUNY) Graphs Spring 2012 60 / 95

Platonic Graphs Graphs that are formed from the vertices and edges of the five regular (Platonic) solids: Tetrahedron: 4 vertices 3-regular graph. Octahedron: 6 vertices 4-regular graph. Cube: 8 vertices 3-regular graph. Icosahedron: 12 vertices 5-regular graph. Dodecahedron: 20 vertices 3-regular graph. Observation: The platonic graphs are d-regular planar graphs. Amotz Bar-Noy (CUNY) Graphs Spring 2012 60 / 95

The Tetrahedron 4 vertices; 6 edges; 4 faces; degree 3 Amotz Bar-Noy (CUNY) Graphs Spring 2012 61 / 95

The Octahedron 6 vertices; 12 edges; 8 faces; degree 4 Amotz Bar-Noy (CUNY) Graphs Spring 2012 62 / 95

The Cube 8 vertices; 12 edges; 6 faces; degree 3 Amotz Bar-Noy (CUNY) Graphs Spring 2012 63 / 95

The Icosahedron 12 vertices; 30 edges; 20 faces; degree 5 Amotz Bar-Noy (CUNY) Graphs Spring 2012 64 / 95

The Dodecahedron 20 vertices; 30 edges; 12 faces; degree 3 Amotz Bar-Noy (CUNY) Graphs Spring 2012 65 / 95

Dual Planar Graphs In the dual planar graph G of a planar graph G, vertices correspond to faces of G and two vertices in G are joined by an edge if the corresponding faces in G share an edge. Amotz Bar-Noy (CUNY) Graphs Spring 2012 66 / 95

Dual Planar Graphs In the dual planar graph G of a planar graph G, vertices correspond to faces of G and two vertices in G are joined by an edge if the corresponding faces in G share an edge. The Octahedron is the dual graph of the Cube. The Cube is the dual graph of the Octahedron. The Icosahedron is the the dual graph of the Dodecahedron. The Dodecahedron is the the dual graph of the Icosahedron. The Tetrahedron is the dual graph of itself. Amotz Bar-Noy (CUNY) Graphs Spring 2012 66 / 95

Duality of the Cube and the Octahedron Amotz Bar-Noy (CUNY) Graphs Spring 2012 67 / 95

Random Graphs Definition I: Each edge exists with probability 0 p 1. Observation: Expected number of edges is E(m) = p ( n 2). Amotz Bar-Noy (CUNY) Graphs Spring 2012 68 / 95

Random Graphs Definition I: Each edge exists with probability 0 p 1. Observation: Expected number of edges is E(m) = p ( n 2). Definition II: A graph with m edges that is selected randomly with a uniform distribution over all graphs with m edges. Amotz Bar-Noy (CUNY) Graphs Spring 2012 68 / 95

Interval Graphs Vertices represent intervals on the x-axis. An edge indicates that two intervals intersect. Amotz Bar-Noy (CUNY) Graphs Spring 2012 69 / 95

Complement Graphs G = (Ṽ, Ẽ) is the complement graph of G = (V, E) if V = Ṽ and (x, y) E (x, y) Ẽ. A graph G is self-complementary if it is isomorphic to G. Amotz Bar-Noy (CUNY) Graphs Spring 2012 70 / 95

Complement Graphs Lemma: At least one of G and G is connected. Proof: Assume G is not connected. The set of vertices V can be partitioned into 2 non-empty sets of vertices A and B such that all the edges between A and B are in G. A complete bipartite graph is connected and therefore G is connected. Amotz Bar-Noy (CUNY) Graphs Spring 2012 71 / 95

Complement Graphs Observation N n = K n. Amotz Bar-Noy (CUNY) Graphs Spring 2012 72 / 95

Complement Graphs Observation K r,s = K r K s. Amotz Bar-Noy (CUNY) Graphs Spring 2012 73 / 95

Complement Graphs Observation C 5 = C 5. Amotz Bar-Noy (CUNY) Graphs Spring 2012 74 / 95

Line Graphs a a b c b c d d In the line graph L(G) = (E, F) of G = (V, E) vertices correspond to edges of G and two vertices in L(G) are joined by an edge if the corresponding edges in G share a vertex. Definition: (e i, e j ) F iff e i = (x, y) and e j = (y, z) for x, y, z V. Observation: L(L(G)) = G is a wrong statement. Amotz Bar-Noy (CUNY) Graphs Spring 2012 75 / 95

Line Graphs Observation a f b c d f a b c e e d L(C n ) = C n. Amotz Bar-Noy (CUNY) Graphs Spring 2012 76 / 95

Line Graphs Observation a b c d a b c d L(P n ) = P n 1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 77 / 95

Line Graphs Observation a b c a b d d c L(S n ) = K n 1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 78 / 95

Social Graphs Definition: The social graph contains all the friendship relations (edges) among n people (vertices). I: In any group of n 2 people, there are 2 people with the same number of friends in the group. II: There exists a group of 5 people for which no 3 are mutual friends and no 3 are mutual strangers. III: Every group of 6 people contains either three mutual friends or three mutual strangers. Amotz Bar-Noy (CUNY) Graphs Spring 2012 79 / 95

Data structure for Graphs Adjacency lists: Θ(m) memory. An adjacency Matrix: Θ(n 2 ) memory. An incident matrix: Θ(n m) memory. Amotz Bar-Noy (CUNY) Graphs Spring 2012 80 / 95

The Adjacency Lists Representation Each vertex is associated with a linked list consisting of all of its neighbors. In a directed graph there are 2 lists: an incoming list and an outgoing list. In a weighted graph each record in the list has an additional field for the weight. Amotz Bar-Noy (CUNY) Graphs Spring 2012 81 / 95

The Adjacency Lists Representation Each vertex is associated with a linked list consisting of all of its neighbors. In a directed graph there are 2 lists: an incoming list and an outgoing list. In a weighted graph each record in the list has an additional field for the weight. Memory: Θ(n + m). Undirected graphs: v Deg(v) = 2m Directed graphs: v OutDeg(v) = v InDeg(v) = m Amotz Bar-Noy (CUNY) Graphs Spring 2012 81 / 95

Example Adjacency Lists A D F E C B A (B, C, D) B (A, C, E) C (A, B, F) D (A, E, F ) E (B, D, F ) F (C, D, E) Amotz Bar-Noy (CUNY) Graphs Spring 2012 82 / 95

The Adjacency Matrix Representation A matrix A of size n n: A[u, v] = 1 if (u, v) or (u v) is an edge. A[u, v] = 0 if (u, v) or (u v) is not an edge. In simple graphs: A[u, u] = 0 In undirected graphs: A[u, v] = A[v, u] In weighted graphs: A[u, v] = w(u, v) Amotz Bar-Noy (CUNY) Graphs Spring 2012 83 / 95

The Adjacency Matrix Representation A matrix A of size n n: A[u, v] = 1 if (u, v) or (u v) is an edge. A[u, v] = 0 if (u, v) or (u v) is not an edge. In simple graphs: A[u, u] = 0 In undirected graphs: A[u, v] = A[v, u] In weighted graphs: A[u, v] = w(u, v) Memory: Θ(n 2 ). Independent of m that could be much smaller than Θ(n 2 ). Amotz Bar-Noy (CUNY) Graphs Spring 2012 83 / 95

Example Adjacency Matrix A D F E C B A B C D E F A 0 1 1 1 0 0 B 1 0 1 0 1 0 C 1 1 0 0 0 1 D 1 0 0 0 1 1 E 0 1 0 1 0 1 F 0 0 1 1 1 0 Amotz Bar-Noy (CUNY) Graphs Spring 2012 84 / 95

The Incident Matrix Representation A matrix A of size n m: A[v, e] = 1 if undirected edge e is incident with v. A[u, e] = 1 and A[v, e] = 1 for a directed edge u v. Otherwise A[v, e] = 0. In simple graphs all the columns are different and each contains exactly 2 non-zero entries. In weighted undirected graphs: A[v, e] = w(e) if edge e is incident with vertex v. Amotz Bar-Noy (CUNY) Graphs Spring 2012 85 / 95

The Incident Matrix Representation A matrix A of size n m: A[v, e] = 1 if undirected edge e is incident with v. A[u, e] = 1 and A[v, e] = 1 for a directed edge u v. Otherwise A[v, e] = 0. In simple graphs all the columns are different and each contains exactly 2 non-zero entries. In weighted undirected graphs: A[v, e] = w(e) if edge e is incident with vertex v. Memory: Θ(n m). Amotz Bar-Noy (CUNY) Graphs Spring 2012 85 / 95

Example Incident Matrix A D F E C B (A, B) (A, C) (A, D) (B, C) (B, E) (C, F ) (D, E) (D, F) (E, F ) A 1 1 1 0 0 0 0 0 0 B 1 0 0 1 1 0 0 0 0 C 0 1 0 1 0 1 0 0 0 D 0 0 1 0 0 0 1 1 0 E 0 0 0 0 1 0 1 0 1 F 0 0 0 0 0 1 0 1 1 Amotz Bar-Noy (CUNY) Graphs Spring 2012 86 / 95

Which Data Structure to Choose? Adjacency matrices are simpler to implement and maintain. Adjacency matrices are better for dense graphs. Adjacency lists are better for sparse graphs. Adjacency lists are better for algorithms whose complexity depends on m. Incident matrices are not efficient for algorithms. Amotz Bar-Noy (CUNY) Graphs Spring 2012 87 / 95

Graphic Sequences The degree d x of vertex x in graph G is the number of neighbors of x in G. The hand-shaking Lemma: n i=1 d i = 2m. Corollary: Number of odd degree vertices is even. The degree sequence of G is S = (d 1,..., d n ). A sequence S = (d 1,..., d n ) is graphic if there exists a graph with n vertices whose degree sequence is S. Amotz Bar-Noy (CUNY) Graphs Spring 2012 88 / 95

Non-Graphic Sequences (3, 3, 3, 3, 3, 3, 3) is not graphic (equivalently, there is no 7-vertex 3-regular graph). Since n i=1 d i is odd. (5, 5, 4, 4, 0) is not graphic. Since there are 5 vertices and therefore the maximum degree could be at most 4. (3, 2, 1, 0) is not graphic. Since there are 3 positive degree vertices and only one vertex with degree 3. Amotz Bar-Noy (CUNY) Graphs Spring 2012 89 / 95

Graphic Sequences Observations I: The sequence (0, 0,..., 0) of length n is graphic. Since it represents the null graph N n. II: In a graphic sequence S = (d 1 d n ) d 1 n 1. III: d d1 +1 > 0 in a graphic sequence of a non-null graph S = (d 1 d n ). Amotz Bar-Noy (CUNY) Graphs Spring 2012 90 / 95

Transformation Let S = (d 1 d n ), then f (S) = (d 2 1 d d1 +1 1, d d1 +2 d n ). Amotz Bar-Noy (CUNY) Graphs Spring 2012 91 / 95

Transformation Let S = (d 1 d n ), then f (S) = (d 2 1 d d1 +1 1, d d1 +2 d n ). Example: S = (5, 4, 3, 3, 2, 1, 1, 1) f (S) = (3, 2, 2, 1, 0, 1, 1) Amotz Bar-Noy (CUNY) Graphs Spring 2012 91 / 95

Lemma S = (d 1 d n ) is graphic iff f (S) is graphic. Amotz Bar-Noy (CUNY) Graphs Spring 2012 92 / 95

Lemma S = (d 1 d n ) is graphic iff f (S) is graphic. To get a graphic representation for S, add a vertex of degree d 1 to the graphic representation of f (S) and connect this vertex to all vertices whose degrees in f (S) are smaller by 1 than those in S. Amotz Bar-Noy (CUNY) Graphs Spring 2012 92 / 95

Lemma S = (d 1 d n ) is graphic iff f (S) is graphic. To get a graphic representation for S, add a vertex of degree d 1 to the graphic representation of f (S) and connect this vertex to all vertices whose degrees in f (S) are smaller by 1 than those in S. To get a graphic representation for f (S), omit a vertex of degree d 1 from the graphic representation of S. Make sure (how?) that this vertex is connected to the vertices whose degrees are d 2,..., d d1 +1. Amotz Bar-Noy (CUNY) Graphs Spring 2012 92 / 95

Algorithm Graphic(S = (d 1 d n 0)) case d 1 = 0 return TRUE (* Obs. I *) case d 1 n return FALSE (* Obs. II *) case d d1 +1 = 0 return FALSE (* Obs. III *) otherwise return Graphic(Sort(f (S))) (* Lemma *) Amotz Bar-Noy (CUNY) Graphs Spring 2012 93 / 95

Algorithm Complexity: O(m) for the transformations since n i=1 d i = 2m. O(n 2 ) for the sorting (merging n times). Amotz Bar-Noy (CUNY) Graphs Spring 2012 94 / 95

Algorithm Complexity: O(m) for the transformations since n i=1 d i = 2m. O(n 2 ) for the sorting (merging n times). Constructing the graph for S = (d 1 d n 0): Follow the part of the proof of the lemma starting with the sequence (0,..., 0) and ending with S. Amotz Bar-Noy (CUNY) Graphs Spring 2012 94 / 95

Example 4 4 3 2 2 2 2 1 I 3 2 1 1 2 2 1 3 2 2 2 1 1 1 II 1 1 1 1 1 1 1 1 1 1 1 1 III 0 1 1 1 1 1 1 1 1 0 IV 0 1 1 0 1 1 0 0 V 0 0 0 VI 1 1 1 1 2 3 1 1 1 2 2 2 1 1 1 3 2 2 4 4 2 III II I Amotz Bar-Noy (CUNY) Graphs Spring 2012 95 / 95