Chapter 11: Graphs and Trees. March 23, 2008

Similar documents
Graph Theory CS/Math231 Discrete Mathematics Spring2015

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

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

CHAPTER 10 GRAPHS AND TREES. Copyright Cengage Learning. All rights reserved.

Varying Applications (examples)

Chapter 3: Paths and Cycles

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

Fundamental Properties of Graphs

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

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.

Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms. 11. Graphs and Trees 1. Aaron Tan. 30 October 3 November 2017

Elements of Graph Theory

Basics of Graph Theory

Graph Theory. 1 Introduction to Graphs. Martin Stynes Department of Mathematics, UCC January 26, 2011

Introduction III. Graphs. Motivations I. Introduction IV

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

2. CONNECTIVITY Connectivity

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

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

Graph and Digraph Glossary

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

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

Introduction to Graphs

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

Discrete mathematics II. - Graphs

Assignment 4 Solutions of graph problems

Number Theory and Graph Theory

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

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

Graph Theory. Part of Texas Counties.

Introduction to Graph Theory

GRAPH THEORY: AN INTRODUCTION

An Introduction to Graph Theory

8.2 Paths and Cycles

(5.2) 151 Math Exercises. Graph Terminology and Special Types of Graphs. Malek Zein AL-Abidin

Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions

MATH 682 Notes Combinatorics and Graph Theory II. One interesting class of graphs rather akin to trees and acyclic graphs is the bipartite graph:

Chapter 3 Trees. Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

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?

6.2. Paths and Cycles

Chapter 2: Graph Theory

Introduction to Engineering Systems, ESD.00. Networks. Lecturers: Professor Joseph Sussman Dr. Afreen Siddiqi TA: Regina Clewlow

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

Math 443/543 Graph Theory Notes 2: Transportation problems

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Exercise set 2 Solutions

Discrete mathematics

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

Math 170- Graph Theory Notes

Math 776 Graph Theory Lecture Note 1 Basic concepts

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

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Artificial Intelligence

Number Theory and Graph Theory

An Introduction to Graph Theory

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

The University of Sydney MATH2969/2069. Graph Theory Tutorial 2 (Week 9) 2008

Foundations of Discrete Mathematics

Treewidth and graph minors

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

Lecture 20 : Trees DRAFT

11.2 Eulerian Trails

North Bank. West Island. East Island. South Bank

Lecture 22 Tuesday, April 10

WUCT121. Discrete Mathematics. Graphs

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

Chapter 5: The Mathematics of Getting Around

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Chapter 2 Graphs. 2.1 Definition of Graphs

Figure 4.1: The evolution of a rooted tree.

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

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

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

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Discrete mathematics

11.9 Connectivity Connected Components. mcs 2015/5/18 1:43 page 419 #427

Chapter 5: Euler Paths and Circuits The Mathematics of Getting Around

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))

BIL694-Lecture 1: Introduction to Graphs

Topic 10 Part 2 [474 marks]

Algorithms. Graphs. Algorithms

The Matrix-Tree Theorem and Its Applications to Complete and Complete Bipartite Graphs

March 20/2003 Jayakanth Srinivasan,

TWO CONTRIBUTIONS OF EULER

Discrete Mathematics and Probability Theory Spring 2015 Vazirani Note 5

Chapter 5: Euler Paths and Circuits The Mathematics of Getting Around

Graph Theory

1 Digraphs. Definition 1

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

Rigidity, connectivity and graph decompositions

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

0.0.1 Network Analysis

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

Massachusetts Institute of Technology 6.042J/18.062J, Fall 02: Mathematics for Computer Science Professor Albert Meyer and Dr. Radhika Nagpal.

14 More Graphs: Euler Tours and Hamilton Cycles

Graph Theory. Chapter 4.

Bipartite Roots of Graphs

Ordinary Differential Equation (ODE)

Transcription:

Chapter 11: Graphs and Trees March 23, 2008

Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees

Graphs: Basic Definitions Informally, a graph is a set of points (called vertices) joined by lines (edges). v 1 e 7 e 1 e 2 e 3 e 5 v 4 v 6 v 5 v 2 v 3 e 4 e 6 Figure: Example of a graph

Definition (a) A graph is a pair (V, E), where V is a set of points (also called vertices), and E is a set of edges. (b) Each edge e E is associated with a pair of points from V. If u and v are associated with the edge e they are called the endpoints of e, we often write uv or {u, v} to represent the edge e.

Definition An edge is said to connect its two endpoints. Two vertices are adjacent if there is an edge connecting them. An edge is said to be incident on each of its endpoints. A graph with no vertices is called empty, otherwise it is called nonempty. A loop is an edge which joins a vertex to itself (i.e. e = {v, v}). Two edges which connect the same set of vertices are said to be parallel. (i.e. e 1 = {v 1, v 2 }, e 2 = {v 1, v 2 }).

Example Consider our first example of a graph: e 7 v 1 e 1 e 2 e 3 e 5 v 4 v 6 v 5 v 2 v 3 e 4 e 6 (a) What are its set of vertices, its set of edges, and the edge-endpoint function? (b) Find all edges incident on v 1, all vertices adjacent to v 1, all loops, all parallel edges, and all isolated vertices.

Solution: (a) Vertex set: V = {v 1, v 2, v 3, v 4, v 5, v 6 } Edge set: E = {e 1, e 2, e 3, e 4, e 5, e 6, e 7 } Edge-endpoint function: Edge Endpoint e 1 {v 1, v 2 } e 2 {v 1, v 3 } e 3 {v 1, v 3 } e 4 {v 2, v 3 } e 5 {v 5, v 6 } e 6 {v 5 } e 7 {v 6 }

(b) All edges incident on v 1 : e 1, e 2, e 3 All vertices adjacent to v 1 : v 2 and v 3 All loops: e 6 and e 7. Parallel edges: e 2 and e 3 Isolated vertices: v 4

Different Representations of the Same Graph It is often possible to draw the same graph in two different ways. To show that two different drawings represent the same graph, we need to find a labelling of vertices and edges which produces the same edge-endpoint function.

Example Show that the following two drawings represent the same graph

Solution: We can label both drawings as follows: v 1 v 1 e1 e 1 e 5 e 3 v 3 v 4 v 5 v 2 e 4 e 5 e 4 e 2 e 2 v 5 v 2 v 4 e 3 v 3 and we have to show that they yield the same edge-endpoint function.

In both cases, the table for the edge-endpoint function is the same: Edge Endpoints e 1 {v 1, v 2 } e 2 {v 2, v 3 } e 3 {v 3, v 4 } e 4 {v 4, v 5 } e 5 {v 5, v 1 } which is what we wanted to show.

Directed Graphs In applications, it is often not the case that we can only go from one vertex, say v 1, to another vertex, e.g. v 2, but not from v 2 to v 1. In those cases, the edges of the graph need to be oriented; i.e. instead of writing {v 1, v 2 } for the edge, we write it as an ordered pair (v 1, v 2 ). Definition (a) A directed graph or digraph is a pair (V, E), where V is a set of points (also called vertices), and E is a set of ordered pairs of points from V called arcs. (b) Each arc e E is associated with an ordered pair of points from V. If u and v are associated with the arc e they are called the endpoints of e; we often write uv or (u, v) to represent the arc e.

Example Figure: Example of a directed graph Vertex set: V = {v 1, v 2, v 3, v 4 } Arc set: E = {(v 4, v 3 ), (v 3, v 2 ), (v 1, v 3 )}

Example: Application of Graphs This is an example of a puzzle in the study of artificial intelligence: suppose that on the left bank of the river there are a farmer, a wolf, a head of cabbage, and a goat. From this initial position, the farmer wants to transport the wolf, the goat and the cabbage to the right bank in a boat. The farmer s boat is big enough for him to only transport one object at a time, other than himself. For obvious reasons, the wolf cannot be left alone with the goat and neither can the goat be left alone with the cabbage. How should the farmer proceed?

We will construct a graph whose vertices are various arrangements that can be reached by a sequence of legal moves starting from the initial position FWGC on the left bank. Figure: Legal moves

We see that one sequence of legal moves which will transport all four objects from the left bank to the right bank, under given restrictions, is: FWGC/ WC/FG FWC/G W /FGC FGW /C G/FWC FG/WC /FWGC

Some Special Graphs Definition A simple graph is a graph that does not contain any loops or parallel edges. Definition The complete graph on n vertices, K n is the simple graph on n vertices, in which every vertex is connected to every other.

Definition Let m and n be positive integers. A complete bipartite graph on (m, n) vertices denoted K m,n is a simple graph with vertices v 1, v 2,..., v m and w 1, w 2,..., w n which satisfies the following properties: 1 There is an edge from each vertex v i to each vertex w j. 2 There is no edge between any two vertices v i and v k. 3 There is no edge between any two vertices w j and w l.

Definition A graph H = (W, F) is said to be a subgraph of a graph G = (V, E) if every vertex of H is also a vertex of G and every edge of H is also an edge of G; i.e. W V and F E. Theorem Every graph G on n vertices is a subgraph of K n.

Degree in a Graph Definition let G be a graph and v a vertex of G. The degree of v, denoted deg(v), is the number of edges that are incident on v, with an edge that is a loop counted twice. The total degree of G is the sum of the degrees of all the vertices of G.

Example Find the degree of each vertex of the graph G in the picture, and find the total degree of G. v 2 e1 e 2 v 1 v 3 v 5 e 3

Solution: deg(v 1 ) = 0 deg(v 2 ) = 2 deg(v 3 ) = 4 total degree of G = deg(v 1 )+deg(v 2 )+deg(v 3 ) = 0+2+4 = 6

In previous example, the total degree of the graph, which was 6, was equal to twice the number of edges (which is 3). In fact, this is true of any graph. Imagine a group of people at a party. Each person shakes hands with a certain number of other partygoers. If we think of this as a graph in which the vertices are people at the party, and we join two vertices if they correspond to a pair of guests who shook hands, the degree of each vertex is the number of people an individual partygoer shook hands with. The total degree of this graph is twice the number of all handshakes.

Theorem (The Handshake Theorem) If G is any graph, then the sum of the degrees of all the vertices of G equals twice the number of the edges of G. In particular, if v 1, v 2,..., v n are the vertices of G, the total degree of G = deg(v 1 ) + deg(v 2 ) +... + deg(v n ) = 2( the number of edges of G ) Corollary The total degree of a graph is an even number

Example Draw a graph with the specified properties or show that such a graph cannot exist. (a) A graph with four vertices of degrees 1,1,2, and 3. (b) A graph with four vertices of degrees 1,1,3, and 3. (c) A simple graph with four vertices of degrees 1,1,3, and 3. Solution: (a) Such a graph is impossible. The total degree of a graph must be an even number, but this graph (if it existed) would have the total degree total degree = 1 + 1 + 2 + 3 = 7

(b) G can be any one of the following four graphs: a b a b d c a b a b d c d c d c (c) Such a graph cannot exist. We will prove this by contradiction.

Proof. Suppose there is a simple graph G with four vertices, call them a, b, c, d, such that a and b have degree 1, and c and d have degree 3. Since deg(c) = 3 and G is simple (i.e. has no loops or parallel edges), c must be connected to every one of the remaining three edges. a b d c

The same has to be true of d, since deg(d) = 3: a b d c But, then, deg(a) 2, and deg(b) 2, which is impossible. Contradiction. Therefore, such a graph cannot exist.

Example A group of 7 computers needs to be connected into a network by laying cables between certain pairs of them. Is it possible to organize the network in such a way that every computer is connected to exactly three other computers? Solution: No. If we think of this network as a graph, we have 7 vertices, call them v 1, v 2,..., v 7 and a certain number of edges between them. However, deg(v i ) = 3, i = 1, 2,..., 7 so total degree of G = 7 3 = 21 which is a contradiction, since the total degree of a graph must be even.

Proposition In any graph there are an even number of vertices of odd degree. Proof. Suppose G is any graph and that we have partitioned its set of vertices V into the set of all vertices of an even degree A, and the set of all vertices of an odd degree B: where V = A B A = {v 1, v 2,..., v k } B = {w 1, w 2,..., w m }

Define Clearly, E = deg(v 1 ) + deg(v 2 ) +... + deg(v k ) O = deg(w 1 ) + deg(w 2 ) +... + deg(w m ) total degree of G = E + O and E is an even number (being a sum of even numbers). Therefore, O is also an even number. But, since every deg(w j ) (j = 1,..., m) is odd, there must be an even number of summands in O. Therefore, the number m of vertices of G which have an odd degree is even

Example Is there a graph with eight vertices of degrees 1, 1, 2, 3, 3, 3, 4, and 4? Solution: No. There are five vertices with an odd degree. (Or: the total degree of the graph is 21, which is also impossible.)

Euler s Königsberg Bridges Problem The town of Königsberg (today s Kaliningrad in Russia) was built at the point where two branches of the Pregel river came together. The town consisted of an island and some surrounding land. These pieces of land were connected by 7 bridges, as shown in the picture: Figure: Map of Königsberg

Problem: Is it possible to walk around the town in such a way that one starts and ends the walk at the same point and crosses every one of the seven bridges only once? Euler solved this problem by converting it into a problem about a particular graph. This was, in a way, the beginning of graph theory.

To solve this problem, we identify each land piece with one vertex of the graph: A, B, C, or D, with seven bridges as the seven edges connecting these four vertices. Figure: Graph modelling the Königsberg Bridges Problem

Suppose the walk starts and ends at some vertex, say D. Every time we come across a vertex in the graph, which is not D, we have to enter it through one edge and leave it via another edge, and we never use the same edge twice. This means, that every vertex other than D must have an even degree, which is clearly not the case. Similarly, we can show that the walk cannot start and end at any other vertex (A, B, or C). This proves that the solution to the problem is negative; i.e. such a walk is not possible.

Walks, Paths, and Circuits Definition Let G = (V, E) be a graph. (a) A walk from vertex v to vertex w is a finite sequence of connected vertices starting at v and ending at w: v 1 e 1 v 2 e 2... e n v n with v i V, e i = {v i, v i+1 } E, v 1 = v and v n = w. This means that we start at v 1, take edge e 1 to vertex v 2, etc. (b) A path from v to w is a walk from v to w which does not contain any repeated edges. (c) A simple path from v to w is a path which contains no repeated vertex. (So there are no repeated vertices or edges.)

Definition (continued) (d) A closed walk is a walk that starts and ends at the same vertex. (So v = w.) (e) A circuit is a closed walk that contains no repeated edge. (So v = w and there are no repeated edges.) (f) A simple circuit is a circuit which does not have any repeated vertices except the first and last. (So v = w and there are no other repeated vertices or edges.)

Example In the graph below determine which of the following walks are paths, simple paths, circuits, or simple circuits: (a) v 1 e 1 v 2 e 3 v 3 e 4 v 3 e 5 v 4 (b) e 1 e 3 e 5 e 5 e 6 (c) v 2 v 3 v 4 v 5 v 3 v 6 v 2 (d) v 2 v 3 v 4 v 5 v 6 v 2 (e) v 2 v 3 v 4 v 5 v 6 v 3 v 2 (f) v 1 e 4 e 5 v 3 v 4 e 3 v 1 e 2 e 1 v 2 e 7 e 6 e 10 e 8 v 6 e 9 v 5

Solution: (a) No repeated edges but there are repeated vertices, so it is a path from v 1 to v 4, but not a simple path. (b) A walk from v 1 to v 5. Not a path since there is a repeated edge. (c) The walk starts and ends at v 2 and has no repeated edges. However, v 3 is a repeated vertex, so it is a circuit but it is not a simple circuit. (d) This is a simple circuit starting and ending at v 2. (e) A closed walk starting and ending at v 2. Not a circuit, since there are repeated edges. (f) This is trivially a simple circuit (since there are no edges - such circuits, containing a single vertex, are called trivial circuits)

Connectedness Definition Let G = (V, E) be a graph. We say that two vertices v, w V are connected in G if there is a walk from v to w. The graph G itself is connected if, and only if, given any two vertices v, w V there is a walk from v to w.

Example Which ones of the following two graphs are connected? v 2 v 5 v 6 v 4 v 2 v 3 v 4 v 5 v 6 v 1 v 1 v 3 v 8 v 7 Solution: The first graph is connected, since there is a walk from any vertex to any other vertex. The second graph is not connected; to see why, notice that for v 4, there is no walk to any other vertex. Also, v 1, for example, is

Definition A graph H is a connected component of a graph G if, and only if, 1 H is a subgraph of G; 2 H is connected; and 3 no connected subgraph of G has H as its proper subgraph (i.e. H is a maximal connected subgraph of G)

Example Find the connected components of the graph v 2 v 5 v 6 v 4 v 1 v 3 v 8 v 7 Solution: graph H 1 : V 1 = {v 1, v 2, v 3 } graph H 2 : V 2 = {v 4 } graph H 3 : V 3 = {v 5, v 6, v 7, v 8 }

Euler Circuits Definition Let G be a graph. An Euler circuit for G is a circuit that contains every vertex and every edge of G. That is, an Euler circuit for G is a sequence of adjacent vertices and edges in G that starts and ends at the same vertex, uses every vertex of G at least once and uses every edge of G exactly once.

Theorem If a graph has an Euler circuit, then every vertex of the graph has even degree. Proof. Suppose G is a graph that has an Euler circuit. Pick an arbitrary vertex v of G. Since the Euler circuit contains every edge of G, it contains all edges incident on v. Every time, when we enter v during a walk through the Euler circuit, we use a previously unused edge and exit v through another previously unused edge. So, the total number of edges incident on v must be even.

Corollary If a graph has a vertex of odd degree, then the graph does not have an Euler circuit. Example v 2 e 1 v 3 e 5 e 6 e 4 e 2 e 7 v 1 e 3 v 4 does not have an Euler circuit, since e.g. v 3 has odd degree (deg(v 3 ) = 3).

Theorem If every vertex of a nonempty graph has even degree and if the graph is connected then the graph has an Euler circuit. Proof. We will prove the theorem by giving an algorithm which, given a connected graph in which every vertex has even degree, produces an Euler circuit C: (a) Pick any vertex v to start C. (b) Pick any sequence of adjacent vertices and edges, starting and ending with v, in which no edges are repeated. Call this circuit C. (c) Check whether C contains every edge and vertex of G. If so, C is an Eulerian circuit, and we can exit the algorithm. If not, continue to the next sequence of steps:

(c1) Remove the edges of C from G and any vertices which become isolated. Call this graph G. (G may not be connected) (c2) Pick a vertex u common to both C and G. (There must be one since G is connected) (c3) Pick a sequence of adjacent edges and points starting and ending at u. This is always possible since the degrees of vertices are all even. So, whenever we reach a vertex there is an edge to leave by. G is finite, so we must eventually return. Call this circuit C. (c4) Set C = C C (c5) Let C = C and go back to the step (c).

Example Check whether the following graph has an Euler circuit and, if so, find one. a d i f j b c e h g

Solution: Notice that deg(a) = deg(b) = deg(c) = deg(f ) = deg(g) = deg(i) = deg(j) = 2 and deg(d) = deg(e) = deg(h) = 4 so, by the previous theorem, this graph has an Euler circuit. Let v = a, and choose C : abcda to be the starting circuit.

a 4 d i 1 3 f j b 2 c e h g Clearly, C is not an Euler circuit yet, since it does not include all the edges. It intersects the rest of the graph at the vertex d. Let C be C : deghjid

Patch C and C to obtain C : abcdeghijda and set C = C. a 1 10 d 3 4 f 9 j 8 i b 2 c e 5 g 6 h 7

C is still not an Euler circuit but it intersects the rest of the graph at e. Let C be C : efhe Patch C and C to get C : abcdefheghijda which is an Euler circuit: a 1 b 13 2 c d 3 4 e 8 5 7 f g 6 9 12 h 10 j 11 i

Theorem A graph G has an Euler circuit if, and only if, G is connected and all vertices of G have even degree.

Definition Let G be a graph, and let v and w be two vertices of G. An Euler path from v to w is a sequence of adjacent edges and vertices that starts at v and ends at w, passes through each vertex of G at least once and traverses each edge of G exactly once. Corollary Let G be a graph, and let v and w be two distinct vertices of G. there is an Euler path from v to w if, and only if, G is connected, v and w have odd degree and all other vertices of G have even degree.

Hamiltonian Circuits Definition A Hamiltonian circuit of a graph G is a simple circuit of G that includes every vertex exactly once. Note: Here, we do not require that every edge be used in the circuit.

An Euler circuit for a graph may not be Hamiltonian; even though every edge is traversed exactly once, the walk may pass through the same vertex several times. Conversely, a Hamiltonian circuit is generally not an Euler circuit since, if there are vertices of degree larger than 2, it will not be possible to traverse all the edges of the graph. Another difference is in the complexity of the problem to determine whether a graph has an Euler or a Hamiltonian circuit; we saw that there is a relatively simple criterion and an algorithm to find determine whether a graph has an Euler circuit and, if it does, to construct it. The problem of checking whether a graph has a Hamiltonian circuit and, if it does, to find it, is far more complicated from the computational point of view.

Problem: What can we say about a graph G if it does have a Hamiltonian circuit? Suppose G has a Hamiltonian circuit C : v 0 e 1 v 1 e 2... v n 1 e n v n Since C is a simple circuit, all v i s are distinct, except for v 0 = v n. Suppose H is a subgraph of G that is obtained by keeping all the vertices v 0, v 1,..., v n (= v 0 ) that appear in C and the edges e 1, e 2,..., e n.

So, H has n vertices and n edges. Also, H is connected (we can find a walk between any two distinct v i and v j ) and every vertex has degree 2 (each v i is is incident on only two edges, e i and e i+1 ) Proposition If a graph G has a nontrivial Hamiltonian circuit, then G has a subgraph with the following properties: 1 H contains every vertex of G. 2 H is connected. 3 H has the same number of edges as vertices. 4 Every vertex of H has degree 2.

Example Show that the following graph does not have a Hamiltonian circuit: a c b e d Solution: Suppose that G has a Hamiltonian circuit. We will try to derive a contradiction. Then, H has a subgraph H which contains all five vertices of G, which is connected, has the same number of edges as vertices (five), and each vertex has degree 2.

Since every vertex in H should have degree 2, we have to delete two edges incident on b in the original graph, so, two of the edges {a, b}, {c, b}, {d, b} or {e, b}. Suppose one of the two deleted edges is, say, {a, b}. Then, the vertex a in H cannot have degree larger than 1, which is a contradiction. Similarly, we can show that no other edge incident on b can be deleted. Therefore, it is not possible to find a subgraph H with the required properties, and G cannot have a Hamiltonian circuit.

Travelling Salesman Problem Problem: A travelling salesman must travel to a number of cities, starting and ending at some given city. The links between cities have a cost associated with them. It is required to find a Hamiltonian circuit which minimizes the cost. Definition A weighted graph is a graph in which each edge has an associated weight (or, cost).

Travelling Salesman Problem: Given a weighted graph G, find a Hamiltonian circuit of least weight. The obvious algorithm for finding such a Hamiltonian circuit is to check every circuit, and compare the costs. There is no known algorithm which is significantly faster than this. For K n the number of possible circuits grows like n!, so this algorithm has running time O(n!). For example, for K 30 the number of circuits to check is roughly 1031. From the point view of computational complexity (a branch of computer science studying complexity of algorithms), this is as difficult as an algorithmically solvable problem can possibly get. There are more efficient algorithms which can detect Hamiltonian circuits whose weight, even though it may not be the smallest possible, are smaller than most possible circuits.

Example A travelling salesman must travel through the following four cities. If he has to start and end his trip in Chicago, how should he organize the trip so that his mileage is the shortest possible?

Solution: For convenience, label the vertices of this graph as C (Chicago), M (Minneapolis), S (St. Louis), and L (Cleveland). Route Total Distance CMSLC 425 + 562 + 541 + 349 = 1877 CMLSC 425 + 774 + 541 + 300 = 2040 CSMLC 300 + 562 + 774 + 349 = 1985 CSLMC 2040 (this is circuit CMLSC backwards) CLMSC 1985 (this is circuit CSMLC backwards) CLSMC 1877 (this is circuit CMSLC backwards) Therefore, the shortest Hamiltonian circuits are CMSLC and CLSMC, with the total distance of 1877 miles.

Matrices and Directed Graphs Definition Given a directed graph G with vertices v 1, v 2,..., v n, we can represent G by an n n matrix A = [a ij ] by defining a ij = the number of edges going from v i to v j. A is called the adjacency matrix of G.

The diagonal entries of the adjacency matrix indicate the loops in the directed graph. If there exist multiple (parallel) edges going from v i to v j, then the entry a ij is a number larger than 1. If we relabel the vertices of G, this will correspond to a permutation of rows and columns.

Example Consider the directed graph e 1 e 3 e 2 v 1 v 2 e 4 e 6 e 5 v 3 Its adjacency matrix is A = 1 0 0 1 1 2 1 0 0

Example Given the 3 3 matrix A = 0 0 0 0 1 1 2 1 0 find a directed graph which has A as its adjacency matrix. Solution: e 5 v 1 v 2 e2 e 3 e 1 e 4 v 3

Matrices and Undirected Graphs Definition Let G be an undirected graph with vertices labelled as v 1, v 2,..., v n. The adjacency matrix of G is the n n matrix A = [a ij ] such that a ij = the number of edges connecting v i to v j.

Example The undirected graph e 2 e 1 v 2 v 1 e 3 e 4 v 3 has as its adjacency matrix. A = 0 1 0 1 1 2 0 2 0

Recall the following definition from matrix theory: Definition An n n matrix A is said to be symmetric if, and only if, I.e. A is equal to its transpose. A = A T For any undirected graph G, the number of edges connecting v i to v j is the same as the number of edges connecting v j to v i. Therefore, the adjacency matrix of any undirected graph is symmetric.

Matrices and Connected Components Example Consider the following graph: v 2 v 5 v 6 v 4 v 1 v 3 v 8 v 7

We have seen earlier that this graph has three connected components: H 1 = {v 1, v 2, v 3 }, H 2 = {v 4 }, H 3 = {v 5, v 6, v 7, v 8 } Its adjacency matrix is: A = 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0

One way to visualize this 8 8 matrix is as follows: it resembles an identity matrix with 1 s on the main diagonal being replaced with the adjacency matrices for H 1, H 2, and H 3. The adjacency matrices for the connected components are: 0 1 0 A 1 = 1 0 1, A 2 = [0], A 3 = 0 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 A 1, A 2, and A 3 are called the blocks of the adjacency matrix A.

Theorem Let G be a graph with connected components H 1, H 2,..., H k. If there are n i vertices in each component H i, and these vertices are numbered consecutively, then the adjacency matrix for G has the form A = A 1 O O... O O O A 2 O... O O O O A 3... O O........ O O O... O A k where each A i is the n i n i adjacency matrix for H i, and O represent zero-matrices of appropriate sizes.

Consider the graph Counting the Walks of Length N Between Two Vertices e 2 e 1 v 2 v 1 e 3 e 4 v 3 Question: How many walks of length 2 can we find that start and end at v 2?

We can start enumerating them systematically: 1 Walks that first go to v 1 : v 2 e 1 v 1 e 1 v 2 2 Walks that first go to v 2 : v 2 e 2 v 2 e 2 v 2 3 Walks that first go to v 3 : v 2 e 3 v 3 e 4 v 2, v 2 e 4 v 3 e 3 v 2, v 2 e 3 v 3 e 3 v 2, and v 2 e 4 v 3 e 4 v 2. So, there are 6 such walks in total.

This problem was easy to answer by hand, systematically enumerating all possible walks of length 2. However, this may be much more complicated for longer walks in a graph with a multitude of edges (with loops and parallel edges, for example). A better approach to answering this type of question is to use the adjacency matrix.

Theorem If G is a graphwith vertices v 1, v 2,..., v m and A is the adjacency matrix of G, then, for each positive integer n, the ij-th entry of A n = the number of walks of length n from v i to v j in G. Proof. We will prove this theorem by induction on n 1. Claim: the ij-th entry of A n = the number of walks of length n from v i to v j in G.

Base step (n = 1): The ij-th entry of A 1 = A is the number of edges connecting v i to v j, which is (obviously) the number of walks of length 1 from v i to v j. Inductive hypothesis: Assume the claim is true for some k 1; i.e. the ij-th entry of A k = the number of walks of length k from v i to v j in G. Inductive step (n = k + 1): We will try to show that the ij-th entry of A k+1 = the number of walks of length k + 1 from v i to v j in G.

Suppose the entries of A k are b ij (i, j = 1,..., n). In other words, b ij is the number of walks of length k from v i to v j. Now, consider A k+1 = A A k The ij-th entry of A k+1 will be n a ik b kj = a i1 b 1j + a i2 b 2j +... + a in b nj k=1 What is the meaning of the product a ik b kj? This is the total number of walks which go from v i to v j which first pass through v k. This is true, since a ik gives us the number of edges from v i to v j from which, then, we can proceed in b kj different ways towards v j.

Therefore, the ij-th entry of A k+1, which is n a ik b kj = a i1 b 1j + a i2 b 2j +... + a in b nj k=1 measures the total number of walks from from v i to v j, since every walk has to pass through some vertex v k first. This proves our claim by induction.

Example Check that the number of walks starting and ending at v 2 in the previous graph is 6, using its adjacency matrix. Solution: A 2 = 0 1 0 1 1 2 0 2 0 0 1 0 1 1 2 0 2 0 = 1 1 2 1 6 2 2 2 4 and since the (2,2)-entry is 6, this is the number of walks of length 2 starting and ending at v 2.

Trees Definition A graph is said to be circuit-free if, and only if, it contains no nontrivial circuits; i.e. no circuits with more than one vertex. A graph is called a tree if, and only if, it is circuit-free and connected. A trivial tree is a tree with only one vertex and an empty tree is a tree with no vertices. A graph is called a forest if, and only if, it is circuit-free but not necessarily connected.

Example Consider the following two graphs The first one is a tree, since it is circuit-free, while the other one is not, since it does contain a circuit of length 3.

Note that a tree must be a simple graph; i.e. a tree cannot contain any loops or parallel edges. Trees are used extensively in problems relating to sorting, searching, syntax parsing in compiler construction, organic chemistry, etc.

Properties of Trees Lemma Any tree that has more than one vertex has at least one vertex of degree 1. Proof. Let G = (V, E) be a nontrivial tree (i.e. V > 1). Pick any vertex v V and randomly follow any path from v without reusing any edges. We cannot return to v (otherwise G would contain a circuit) and we must eventually terminate (since V is finite). The only way we can get stuck is if we hit a vertex of degree 1.

Definition 1 A vertex of degree 1 in a tree is called a leaf, or terminal vertex. 2 A vertex of degree greater than 1 in a tree is called an internal vertex or a branch vertex.

Theorem For any positive integer n, any tree with n vertices has n 1 edges. Proof. We will prove this theorem by induction. Base Case (n = 1): If n = 1, this is the trivial tree with 0 edges. So, the claim is true for n = 1. Inductive Hypothesis: Let n = k and assume that every tree with k vertices has exactly k 1 edges.

Inductive Step: Let n = k + 1 and assume T is a tree with k + 1 vertices. We want to show that T has (k + 1) 1 = k edges. Let v be a leaf in T (which exists, by the previous Lemma). Consider the graph T, obtained by deleting the vertex v and the only edge coming out of v from T. T is still a tree (obvious), so, since it has k vertices, it must have exactly k 1 edges. This means that in T there were (k 1) + 1 = k edges, before the deletion. This proves the statement of the theorem.

Example By the previous theorem, a graph with six vertices and seven edges cannot be a tree. Example Find all trees with four vertices. Solution: Such a tree must have three edges, therefore its total degree is 2 3 = 6, so the only possibilities for degree sequences are 1, 1, 1, 3 and 1, 1, 2, 2

Theorem If G is a connected graph with n vertices and n 1 edges, then G is a tree. Proof. Let G be a connected graph with n vertices and n 1 edges. We will prove the theorem by contradiction. Suppose that G is not a tree, thus G has a circuit. Remove an edge from this circuit to get a new graph G. If G still has circuits repeat this process of removing edges from circuits until we get a circuit free graph. Note that removing edges from a circuit never disconnects the graph. Suppose we have repeated this process k times, and we are left with a tree with n vertices and n 1 k edges. But this contradicts the previous Theorem.

Example The previous theorem can fail if we do not assume that G is connected; namely, there are disconnected graphs with n vertices and n 1 edges which are not trees: v 1 v 4 v 5 v 2 v 3 This graph has 5 vertices and 4 edges, yet is not a tree since it contains a circuit.

Rooted Trees Definition A rooted tree is a tree with a distinguished vertex called the root. The level of a vertex in a rooted tree is the number of edges in the unique path from the vertex to the root. The height of a rooted tree is the maximum level of any vertex in the tree. Given an internal vertex in a rooted tree its children are those vertices adjacent to it and one level higher. If u and v are vertices in a rooted tree, with u a child of v, then v is called the parent of u.

Definition (Continued) Two vertices which are children of the same vertex are called siblings. Given two vertices u and v in a rooted tree, if u lies on the path from v to the root then u is called an ancestor of v, and v is called a descendent of u.

Example Consider the rooted tree v 0 v 1 v 2 v 3 v 4 v 5 v 6 v 7 v 8 v 9 v 10

1 The level of v 5 is 2. 2 The level of v 0 (the root) is 0. 3 The height of the tree is 3. 4 The children of v 3 are v 5 and v 6. 5 The parent of v 2 is v 0. 6 The siblings of v 8 are v 7 and v 9. 7 The descendants of v 3 are v 5, v 6, and v 10.

Binary Trees Definition 1 A binary tree is a rooted tree in which each vertex has at most two children. 2 A full binary tree is a binary tree in which each internal vertex has exactly two children. 3 The children of a vertex v in a binary tree can be identified as the left child and right child of v, respectively. 4 Given an internal vertex, v, of a binary tree the left subtree is the binary tree consisting of all the descendants of the left child of v, whose root is left child of v. Similarly for the right subtree.

Theorem For any positive integer n, if T is a full binary tree with n internal vertices, then T has n + 1 leaves and a total of 2n + 1 vertices. Proof. Let T be a full binary tree with n internal vertices. Every internal vertex of T has 2 children, so the number of vertices that have a parent is equal to twice the number of internal vertices, or 2n. Let m be the total number of vertices of T.

m = The number of vertices which have a parent + those that don t = 2n + 1 (the root) = The number of internal vertices + The number of leaves = n + The number of leaves So, the number of leaves is (2k + 1) k = k + 1

Theorem If T is a binary tree with t leaves and height h then t 2 h (i.e. log 2 t h). Proof. We will prove this claim by strong induction on h: If T is a binary tree with t leaves and height h then t 2 h Base Step (h = 0): If T is a binary tree of height h = 0, then it is trivial (i.e. it consists of the root only), so t = 1 = 2 0, which makes the claim true. Inductive Hypothesis: Suppose that every binary tree with t leaves and height h < k, then t 2 h.

Inductive Step: Assume that T is a binary tree of height k > 0. Consider the root of the tree, call it v 0. For every child of v (there are at most two of them, v l and v r ), consider the subtree whose root is that child. Therefore, T will have at most two such subtrees, the left one, and the right one, call them T l and T r. Call the number of leaves in those two subtrees t l and t r. Obviously, t = t l + t r By inductive hypothesis, since T l and T r are of height at most k 1, t l 2 k 1, t r 2 k 1 Therefore, t = t l + t r 2 k 1 + 2 k 1 = 2 2 k 1 = 2 k which proves the theorem.

Example Determine whether the following graphs exist or not: (a) A full binary tree with eight internal vertices and seven terminal vertices? (b) A binary tree of height 4 with eighteen terminal vertices? Solution: (a) No. A full binary tree with eight internal vertices must have 8 + 1 = 9 terminal vertices. (b) No. A binary tree of height 4 can have at most terminal vertices. 2 4 = 16