Chapter 10, graph theory i, Study notes of Discrete Mathematics

This chapter to help to pass a great grade

Typology: Study notes

2025/2026

Uploaded on 01/02/2026

ahmed-alruzaiqi
ahmed-alruzaiqi 🇴🇲

1 document

1 / 104

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
10
CHAPTER
Graphs
10.1 Graphs and
Graph Models
10.2 Graph
Terminology
and Special
Types of
Graphs
10.3 Representing
Graphs and
Graph
Isomorphism
10.4 Connectivity
10.5 Euler and
Hamilton
Paths
10.6 Shortest-Path
Problems
10.7 Planar Graphs
10.8 Graph
Coloring
Graphs are discrete structures consisting of vertices and edges that connect these vertices.
Therearedifferentkindsofgraphs,dependingonwhetheredgeshavedirections,whether
multiple edges can connect the same pair of vertices, and whether loops are allowed. Problems
inalmosteveryconceivabledisciplinecanbesolvedusinggraphmodels.Wewillgiveexamples
toillustrate how graphs areused as models in a variety of areas. For instance, we will show how
graphs are used to represent the competition of different species in an ecological niche, how
graphs are used to represent who influences whom in an organization, and how graphs are used
torepresentthe outcomes of round-robin tournaments. Wewilldescribe howgraphs can be used
tomodel acquaintanceships between people,collaboration between researchers, telephonecalls
betweentelephone numbers, and links between websites. We will show how graphs can be used
to model roadmaps and the assignment of jobs to employees of an organization.
Using graph models, we can determine whether it is possible to walk down all the streets
in a city without going down a street twice, and we can find the number of colors needed to
color the regions of a map. Graphs can be used to determine whether a circuit can be imple-
mentedonaplanar circuit board.Wecandistinguishbetweentwochemicalcompoundswiththe
same molecular formula but different structures using graphs. We can determine whether two
computers are connected by a communications link using graph models of computer networks.
Graphs with weights assigned to their edges can be used to solve problems such as finding the
shortestpath between two citiesin a transportation network.Wecanalsouse graphs to schedule
exams and assign channels to television stations. This chapter will introduce the basic concepts
ofgraph theory and present many different graph models. To solve the wide varietyofproblems
that can be studied using graphs, we will introduce many different graph algorithms. We will
also study the complexity of these algorithms.
10.1 Graphs and Graph Models
We begin with the definition of a graph.
DEFINITION 1 Agraph G=(V , E) consists of V, a nonempty set of vertices (or nodes) and E, a set of
edges. Each edge has either one or two vertices associated with it, called its endpoints.An
edge is said to connect its endpoints.
Remark: The set of vertices Vof a graph Gmay be infinite. A graph with an infinite vertex
set or an infinite number of edges is called an infinite graph, and in comparison, a graph with
a finite vertex set and a finite edge set is called a finite graph. In this book we will usually
consider only finite graphs.
Now suppose that a network is made up of data centers and communication links between
computers.Wecanrepresentthelocationof each datacenterbyapointandeachcommunications
link by a line segment, as shown in Figure 1.
This computer network can be modeled using a graph in which the vertices of the graph
representthe data centers and the edgesrepresent communication links. In general,we visualize
641
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Chapter 10, graph theory i and more Study notes Discrete Mathematics in PDF only on Docsity!

C H A P T E R

Graphs

10.1 Graphs and Graph Models

10.2 Graph Terminology and Special Types of Graphs

10.3 Representing Graphs and Graph Isomorphism

10.4 Connectivity

10.5 Euler and Hamilton Paths

10.6 Shortest-Path Problems

10.7 Planar Graphs

10.8 Graph Coloring

G

raphs are discrete structures consisting of vertices and edges that connect these vertices. There are different kinds of graphs, depending on whether edges have directions, whether multiple edges can connect the same pair of vertices, and whether loops are allowed. Problems in almost every conceivable discipline can be solved using graph models. We will give examples to illustrate how graphs are used as models in a variety of areas. For instance, we will show how graphs are used to represent the competition of different species in an ecological niche, how graphs are used to represent who influences whom in an organization, and how graphs are used to represent the outcomes of round-robin tournaments. We will describe how graphs can be used to model acquaintanceships between people, collaboration between researchers, telephone calls between telephone numbers, and links between websites. We will show how graphs can be used to model roadmaps and the assignment of jobs to employees of an organization. Using graph models, we can determine whether it is possible to walk down all the streets in a city without going down a street twice, and we can find the number of colors needed to color the regions of a map. Graphs can be used to determine whether a circuit can be imple- mented on a planar circuit board. We can distinguish between two chemical compounds with the same molecular formula but different structures using graphs. We can determine whether two computers are connected by a communications link using graph models of computer networks. Graphs with weights assigned to their edges can be used to solve problems such as finding the shortest path between two cities in a transportation network. We can also use graphs to schedule exams and assign channels to television stations. This chapter will introduce the basic concepts of graph theory and present many different graph models. To solve the wide variety of problems that can be studied using graphs, we will introduce many different graph algorithms. We will also study the complexity of these algorithms.

10.1 Graphs and Graph Models

We begin with the definition of a graph.

DEFINITION 1 A graph G = (V , E) consists of V , a nonempty set of vertices (or nodes ) and E, a set of

edges. Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its endpoints.

Remark: The set of vertices V of a graph G may be infinite. A graph with an infinite vertex set or an infinite number of edges is called an infinite graph , and in comparison, a graph with a finite vertex set and a finite edge set is called a finite graph. In this book we will usually consider only finite graphs.

Now suppose that a network is made up of data centers and communication links between computers. We can represent the location of each data center by a point and each communications link by a line segment, as shown in Figure 1. This computer network can be modeled using a graph in which the vertices of the graph represent the data centers and the edges represent communication links. In general, we visualize 641

642 10 / Graphs

San Francisco

Los Angeles

Denver

Detroit

Chicago

New York

Washington

FIGURE 1 A Computer Network.

graphs by using points to represent vertices and line segments, possibly curved, to represent edges, where the endpoints of a line segment representing an edge are the points representing the endpoints of the edge. When we draw a graph, we generally try to draw edges so that they do not cross. However, this is not necessary because any depiction using points to represent vertices and any form of connection between vertices can be used. Indeed, there are some graphs that cannot be drawn in the plane without edges crossing (see Section 10.7). The key point is that the way we draw a graph is arbitrary, as long as the correct connections between vertices are depicted. Note that each edge of the graph representing this computer network connects two different vertices. That is, no edge connects a vertex to itself. Furthermore, no two different edges connect the same pair of vertices. A graph in which each edge connects two different vertices and where no two edges connect the same pair of vertices is called a simple graph. Note that in a simple graph, each edge is associated to an unordered pair of vertices, and no other edge is associated to this same edge. Consequently, when there is an edge of a simple graph associated to {u, v }, we can also say, without possible confusion, that {u, v } is an edge of the graph. A computer network may contain multiple links between data centers, as shown in Figure 2. To model such networks we need graphs that have more than one edge connecting the same pair of vertices. Graphs that may have multiple edges connecting the same vertices are called multigraphs. When there are m different edges associated to the same unordered pair of vertices {u, v }, we also say that {u, v } is an edge of multiplicity m. That is, we can think of this set of edges as m different copies of an edge {u, v }.

San Francisco

Los Angeles

Denver

Detroit Chicago New^ York

Washington

FIGURE 2 A Computer Network with Multiple Links between Data Centers.

Sometimes a communications link connects a data center with itself, perhaps a feedback loop for diagnostic purposes. Such a network is illustrated in Figure 3. To model this network we

San Francisco

Los Angeles

Denver

Detroit Chicago New York

Washington

FIGURE 3 A Computer Network with Diagnostic Links.

644 10 / Graphs

TABLE 1 Graph Terminology.

Type Edges Multiple Edges Allowed? Loops Allowed?

Simple graph Undirected No No Multigraph Undirected Yes No Pseudograph Undirected Yes Yes Simple directed graph Directed No No Directed multigraph Directed Yes Yes Mixed graph Directed and undirected Yes Yes

For some models we may need a graph where some edges are undirected, while others are directed. A graph with both directed and undirected edges is called a mixed graph. For example, a mixed graph might be used to model a computer network containing links that operate in both directions and other links that operate only in one direction. This terminology for the various types of graphs is summarized in Table 1. We will some- times use the term graph as a general term to describe graphs with directed or undirected edges (or both), with or without loops, and with or without multiple edges. At other times, when the context is clear, we will use the term graph to refer only to undirected graphs. Because of the relatively modern interest in graph theory, and because it has applications to a wide variety of disciplines, many different terminologies of graph theory have been introduced. The reader should determine how such terms are being used whenever they are encountered. The terminology used by mathematicians to describe graphs has been increasingly standardized, but the terminology used to discuss graphs when they are used in other disciplines is still quite varied. Although the terminology used to describe graphs may vary, three key questions can help us understand the structure of a graph:

 Are the edges of the graph undirected or directed (or both)?  (^) If the graph is undirected, are multiple edges present that connect the same pair of vertices? If the graph is directed, are multiple directed edges present?  (^) Are loops present?

Answering such questions helps us understand graphs. It is less important to remember the particular terminology used.

Graph Models

Graphs are used in a wide variety of models. We began this section by describing how to construct graph models of communications networks linking data centers. We will complete this section by describing some diverse graph models for some interesting applications. We will return to many of these applications later in this chapter and in Chapter 11. We will introduce additional

Can you find a subject to graph models in subsequent sections of this and later chapters. Also, recall that directed graph which graph theory has not been applied?

models for some applications were introduced in Chapter 9. When we build a graph model, we need to make sure that we have correctly answered the three key questions we posed about the structure of a graph.

SOCIAL NETWORKS Graphs are extensively used to model social structures based on dif- ferent kinds of relationships between people or groups of people. These social structures, and the graphs that represent them, are known as social networks. In these graph models, individuals or organizations are represented by vertices; relationships between individuals or organizations are represented by edges. The study of social networks is an extremely active multidisciplinary area, and many different types of relationships between people have been studied using them.

10.1 Graphs and Graph Models 645

Jan (^) Todd

Eduardo

Kamlesh

Lila Liz

Kari (^) Shaquira

Joel Koko

Kamini Ching

Amy

Gail

Steve

Paula

FIGURE 6 An Acquaintanceship Graph.

Linda Brian

Deborah Fred Yvonne

FIGURE 7 An Influence Graph.

We will introduce some of the most commonly studied social networks here. More information about social networks can be found in [Ne10] and [EaKl10].

EXAMPLE 1 Acquaintanceship and Friendship Graphs We can use a simple graph to represent whether

two people know each other, that is, whether they are acquainted, or whether they are friends (either in the real world in the virtual world via a social networking site such as Facebook). Each person in a particular group of people is represented by a vertex. An undirected edge is used to connect two people when these people know each other, when we are concerned only with acquaintanceship, or whether they are friends. No multiple edges and usually no loops are used. (If we want to include the notion of self-knowledge, we would include loops.) A small acquaintanceship graph is shown in Figure 6. The acquaintanceship graph of all people in the world has more than six billion vertices and probably more than one trillion edges! We will discuss this graph further in Section 10.4. ▲

EXAMPLE 2 Influence Graphs In studies of group behavior it is observed that certain people can influence

the thinking of others. A directed graph called an influence graph can be used to model this behavior. Each person of the group is represented by a vertex. There is a directed edge from vertex a to vertex b when the person represented by vertex a can influence the person represented by vertex b. This graph does not contain loops and it does not contain multiple directed edges. An example of an influence graph for members of a group is shown in Figure 7. In the group modeled by this influence graph, Deborah cannot be influenced, but she can influence Brian, Fred, and Linda. Also, Yvonne and Brian can influence each other. ▲

EXAMPLE 3 Collaboration Graphs A collaboration graph is used to model social networks where two

people are related by working together in a particular way. Collaboration graphs are simple graphs, as edges in these graphs are undirected and there are no multiple edges or loops. Vertices in these graphs represent people; two people are connected by an undirected edge when the people have collaborated. There are no loops nor multiple edges in these graphs. The Hollywood graph is a collaborator graph that represents actors by vertices and connects two actors with an edge if they have worked together on a movie or television show. The Hollywood graph is a huge graph with more than 1.5 million vertices (as of early 2011). We will discuss some aspects of the Hollywood graph later in Section 10.4. In an academic collaboration graph , vertices represent people (perhaps restricted to mem- bers of a certain academic community), and edges link two people if they have jointly published a paper. The collaboration graph for people who have published research papers in mathematics was found in 2004 to have more than 400,000 vertices and 675,000 edges, and these numbers have grown considerably since then. We will have more to say about this graph in Section 10.4. Collaboration graphs have also been used in sports, where two professional athletes are consid- ered to have collaborated if they have ever played on the same team during a regular season of their sport.^ ▲

10.1 Graphs and Graph Models 647

first document cites the second in its citation list. (In an academic paper, the citation list is the bibliography, or list of references; in a patent it is the list of previous patents that are cited; and in a legal opinion it is the list of previous opinions cited.) A citation graph is a directed graph without loops or multiple edges. ▲

SOFTWARE DESIGN APPLICATIONS Graph models are useful tools in the design of software. We will briefly describe two of these models here.

EXAMPLE 7 Module Dependency Graphs One of the most important tasks in designing software is how to

structure a program into different parts, or modules. Understanding how the different modules of a program interact is essential not only for program design, but also for testing and maintenance of the resulting software. A module dependency graph provides a useful tool for understanding how different modules of a program interact. In a program dependency graph, each module is represented by a vertex. There is a directed edge from a module to a second module if the second module depends on the first. An example of a program dependency graph for a web browser is shown in Figure 9. ▲

EXAMPLE 8 Precedence Graphs and Concurrent Processing Computer programs can be executed more

rapidly by executing certain statements concurrently. It is important not to execute a statement that requires results of statements not yet executed. The dependence of statements on previous statements can be represented by a directed graph. Each statement is represented by a vertex, and there is an edge from one statement to a second statement if the second statement cannot be executed before the first statement. This resulting graph is called a precedence graph. A computer program and its graph are displayed in Figure 10. For instance, the graph shows that statement S 5 cannot be executed before statements S 1 , S 2 , and S 4 are executed. ▲

TRANSPORTATION NETWORKS We can use graphs to model many different types of transportation networks, including road, air, and rail networks, as well shipping networks.

EXAMPLE 9 Airline Routes We can model airline networks by representing each airport by a vertex. In

particular, we can model all the flights by a particular airline each day using a directed edge to represent each flight, going from the vertex representing the departure airport to the vertex representing the destination airport. The resulting graph will generally be a directed multigraph, as there may be multiple flights from one airport to some other airport during the same day. ▲

EXAMPLE 10 Road Networks Graphs can be used to model road networks. In such models, vertices repre-

sent intersections and edges represent roads. When all roads are two-way and there is at most one road connecting two intersections, we can use a simple undirected graph to model the road network. However, we will often want to model road networks when some roads are one-way and when there may be more than one road between two intersections. To build such models, we use undirected edges to represent two-way roads and we use directed edges to represent

main

page network

display parser protocol

abstract syntax tree

FIGURE 9 A Module Dependency Graph.

S 1 S 2 S 3 S 4 S 5 S 6

a := 0 b := 1 c := a + 1 d := b + a e := d + 1 e := c + d S 1

S 6

S 5

S (^3) S 4

S 2

FIGURE 10 A Precedence Graph.

648 10 / Graphs

one-way roads. Multiple undirected edges represent multiple two-way roads connecting the same two intersections. Multiple directed edges represent multiple one-way roads that start at one intersection and end at a second intersection. Loops represent loop roads. Mixed graphs are needed to model road networks that include both one-way and two-way roads. ▲

BIOLOGICAL NETWORKS Many aspects of the biological sciences can be modeled using graphs.

EXAMPLE 11 Niche Overlap Graphs in Ecology Graphs are used in many models involving the interaction

of different species of animals. For instance, the competition between species in an ecosystem can be modeled using a niche overlap graph. Each species is represented by a vertex. An undirected edge connects two vertices if the two species represented by these vertices compete (that is, some of the food resources they use are the same). A niche overlap graph is a simple graph because no loops or multiple edges are needed in this model. The graph in Figure 11 models the ecosystem of a forest. We see from this graph that squirrels and raccoons compete but that crows and shrews do not. ▲

EXAMPLE 12 Protein Interaction Graphs A protein interaction in a living cell occurs when two or more

proteins in that cell bind to perform a biological function. Because protein interactions are crucial for most biological functions, many scientists work on discovering new proteins and understanding interactions between proteins. Protein interactions within a cell can be modeled using a protein interaction graph (also called a protein–protein interaction network ), an undirected graph in which each protein is represented by a vertex, with an edge connecting the vertices representing each pair of proteins that interact. It is a challenging problem to determine genuine protein interactions in a cell, as experiments often produce false positives, which con- clude that two proteins interact when they really do not. Protein interaction graphs can be used to deduce important biological information, such as by identifying the most important proteins for various functions and the functionality of newly discovered proteins. Because there are thousands of different proteins in a typical cell, the protein interaction graph of a cell is extremely large and complex. For example, yeast cells have more than 6, proteins, and more than 80,000 interactions between them are known, and human cells have more than 100,000 proteins, with perhaps as many as 1,000,000 interactions between them. Additional vertices and edges are added to a protein interaction graph when new proteins and interactions between proteins are discovered. Because of the complexity of protein interac- tion graphs, they are often split into smaller graphs called modules that represent groups of proteins that are involved in a particular function of a cell. Figure 12 illustrates a module of the protein interaction graph described in [Bo04], comprising the complex of proteins that de- grade RNA in human cells. To learn more about protein interaction graphs, see [Bo04], [Ne10], and [Hu07]. ▲

Hawk Owl Raccoon

Crow

Opossum Squirrel

Shrew (^) Woodpecker Mouse

FIGURE 11 A Niche Overlap Graph.

Q9Y3A

RRP 42

RRP 41

RRP 40

PM/Sci2 RRP^46

RRP 44

RRP 4

RRP 43

FIGURE 12 A Module of a Protein Interaction Graph.

650 10 / Graphs

For Exercises 3–9, determine whether the graph shown has directed or undirected edges, whether it has multiple edges, and whether it has one or more loops. Use your answers to determine the type of graph in Table 1 this graph is.

3. a^ b

c d

4. a^ b

c d

5. a b

c d

6. a^ b

c d

e

7. (^) b c

a e d

8. (^) a e

d

b c

9. (^) b

c

e d

f

a

10. For each undirected graph in Exercises 3–9 that is not simple, find a set of edges to remove to make it simple. 11. Let G be a simple graph. Show that the relation R on the set of vertices of G such that uR v if and only if there is an edge associated to {u, v } is a symmetric, irreflexive relation on G. 12. Let G be an undirected graph with a loop at every vertex. Show that the relation R on the set of vertices of G such that uR v if and only if there is an edge associated to {u, v } is a symmetric, reflexive relation on G. 13. The intersection graph of a collection of sets A 1 , A 2 ,... , An is the graph that has a vertex for each of these sets and has an edge connecting the vertices representing two sets if these sets have a nonempty intersection. Con- struct the intersection graph of these collections of sets. a) A 1 = { 0 , 2 , 4 , 6 , 8 }, A 2 = { 0 , 1 , 2 , 3 , 4 }, A 3 = { 1 , 3 , 5 , 7 , 9 }, A 4 = { 5 , 6 , 7 , 8 , 9 }, A 5 = { 0 , 1 , 8 , 9 } b) A 1 = {... , − 4 , − 3 , − 2 , − 1 , 0 }, A 2 = {... , − 2 , − 1 , 0 , 1 , 2 ,.. .}, A 3 = {... , − 6 , − 4 , − 2 , 0 , 2 , 4 , 6 ,.. .}, A 4 = {... , − 5 , − 3 , − 1 , 1 , 3 , 5 ,.. .}, A 5 = {... , − 6 , − 3 , 0 , 3 , 6 ,.. .}

c) A 1 = {x | x < 0 }, A 2 = {x | − 1 < x < 0 }, A 3 = {x | 0 < x < 1 }, A 4 = {x | − 1 < x < 1 }, A 5 = {x | x > − 1 }, A 6 = R

14. Use the niche overlap graph in Figure 11 to determine the species that compete with hawks. 15. Construct a niche overlap graph for six species of birds, where the hermit thrush competes with the robin and with the blue jay, the robin also competes with the mockingbird, the mockingbird also competes with the blue jay, and the nuthatch competes with the hairy wood- pecker. 16. Draw the acquaintanceship graph that represents that Tom and Patricia, Tom and Hope, Tom and Sandy, Tom and Amy, Tom and Marika, Jeff and Patricia, Jeff and Mary, Patricia and Hope, Amy and Hope, and Amy and Marika know each other, but none of the other pairs of people listed know each other. 17. We can use a graph to represent whether two people were alive at the same time. Draw such a graph to represent whether each pair of the mathematicians and computer scientists with biographies in the first five chapters of this book who died before 1900 were contemporaneous. (Assume two people lived at the same time if they were alive during the same year.) 18. Who can influence Fred and whom can Fred influence in the influence graph in Example 2? 19. Construct an influence graph for the board members of a company if the President can influence the Director of Re- search and Development, the Director of Marketing, and the Director of Operations; the Director of Research and Development can influence the Director of Operations; the Director of Marketing can influence the Director of Operations; and no one can influence, or be influenced by, the Chief Financial Officer. 20. Which other teams did Team 4 beat and which teams beat Team 4 in the round-robin tournament represented by the graph in Figure 13? 21. In a round-robin tournament the Tigers beat the Blue Jays, the Tigers beat the Cardinals, the Tigers beat the Orioles, the Blue Jays beat the Cardinals, the Blue Jays beat the Orioles, and the Cardinals beat the Orioles. Model this outcome with a directed graph. 22. Construct the call graph for a set of seven telephone numbers 555-0011, 555-1221, 555-1333, 555-8888, 555-2222, 555-0091, and 555-1200 if there were three calls from 555-0011 to 555-8888 and two calls from 555-8888 to 555-0011, two calls from 555-2222 to 555-0091, two calls from 555-1221 to each of the other numbers, and one call from 555-1333 to each of 555-0011, 555-1221, and 555-1200. 23. Explain how the two telephone call graphs for calls made during the month of January and calls made during the month of February can be used to determine the new tele- phone numbers of people who have changed their tele- phone numbers.

10.2 Graph Terminology and Special Types of Graphs 651

24. a) Explain how graphs can be used to model electronic mail messages in a network. Should the edges be di- rected or undirected? Should multiple edges be al- lowed? Should loops be allowed? b) Describe a graph that models the electronic mail sent in a network in a particular week. 25. How can a graph that models e-mail messages sent in a network be used to find people who have recently changed their primary e-mail address? 26. How can a graph that models e-mail messages sent in a network be used to find electronic mail mailing lists used to send the same message to many different e-mail addresses? 27. Describe a graph model that represents whether each per- son at a party knows the name of each other person at the party. Should the edges be directed or undirected? Should multiple edges be allowed? Should loops be allowed? 28. Describe a graph model that represents a subway system in a large city. Should edges be directed or undirected? Should multiple edges be allowed? Should loops be al- lowed? 29. For each course at a university, there may be one or more other courses that are its prerequisites. How can a graph be used to model these courses and which courses are pre- requisites for which courses? Should edges be directed or undirected? Looking at the graph model, how can we find courses that do not have any prerequisites and how can we find courses that are not the prerequisite for any other courses? 30. Describe a graph model that represents the positive rec- ommendations of movie critics, using vertices to repre-

sent both these critics and all movies that are currently being shown.

31. Describe a graph model that represents traditional mar- riages between men and women. Does this graph have any special properties? 32. Which statements must be executed before S 6 is executed in the program in Example 8? (Use the precedence graph in Figure 10.) 33. Construct a precedence graph for the following program: S 1 : x := 0 S 2 : x := x + 1 S 3 : y := 2 S 4 : z := y S 5 : x := x + 2 S 6 : y := x + z S 7 : z := 4 34. Describe a discrete structure based on a graph that can be used to model airline routes and their flight times. [ Hint: Add structure to a directed graph.] 35. Describe a discrete structure based on a graph that can be used to model relationships between pairs of individuals in a group, where each individual may either like, dislike, or be neutral about another individual, and the reverse relationship may be different. [ Hint: Add structure to a directed graph. Treat separately the edges in opposite di- rections between vertices representing two individuals.] 36. Describe a graph model that can be used to represent all forms of electronic communication between two people in a single graph. What kind of graph is needed?

10.2 Graph Terminology and Special Types of Graphs

Introduction

We introduce some of the basic vocabulary of graph theory in this section. We will use this vo- cabulary later in this chapter when we solve many different types of problems. One such problem involves determining whether a graph can be drawn in the plane so that no two of its edges cross. Another example is deciding whether there is a one-to-one correspondence between the vertices of two graphs that produces a one-to-one correspondence between the edges of the graphs. We will also introduce several important families of graphs often used as examples and in models. Several important applications will be described where these special types of graphs arise.

Basic Terminology

First, we give some terminology that describes the vertices and edges of undirected graphs.

DEFINITION 1 Two vertices u and v in an undirected graph G are called adjacent (or neighbors ) in G if u

and v are endpoints of an edge e of G. Such an edge e is called incident with the vertices u and v and e is said to connect u and v.

10.2 Graph Terminology and Special Types of Graphs 653

ecosystem. Finally, the vertex representing a species is isolated if this species does not compete with any other species in the ecosystem. For instance, the degree of the vertex representing the squirrel in the niche overlap graph in Figure 11 in Section 10.1 is four, because the squirrel competes with four other species: the crow, the opossum, the raccoon, and the woodpecker. In this niche overlap graph, the mouse is the only species represented by a pendant vertex, because the mouse competes only with the shrew and all other species compete with at least two other species. There are no isolated vertices in the graph in this niche overlap graph because every species in this ecosystem competes with at least one other species. ▲

What do we get when we add the degrees of all the vertices of a graph G = (V , E)? Each edge contributes two to the sum of the degrees of the vertices because an edge is incident with exactly two (possibly equal) vertices. This means that the sum of the degrees of the vertices is twice the number of edges. We have the result in Theorem 1, which is sometimes called the handshaking theorem (and is also often known as the handshaking lemma), because of the analogy between an edge having two endpoints and a handshake involving two hands.

THEOREM 1 THE HANDSHAKING THEOREM Let G = (V , E) be an undirected graph with m

edges. Then

2 m =

v ∈V

deg( v ).

(Note that this applies even if multiple edges and loops are present.)

EXAMPLE 3 How many edges are there in a graph with 10 vertices each of degree six?

Solution: Because the sum of the degrees of the vertices is 6 · 10 = 60, it follows that 2m = 60 where m is the number of edges. Therefore, m = 30. ▲

Theorem 1 shows that the sum of the degrees of the vertices of an undirected graph is even. This simple fact has many consequences, one of which is given as Theorem 2.

THEOREM 2 An undirected graph has an even number of vertices of odd degree.

Proof: Let V 1 and V 2 be the set of vertices of even degree and the set of vertices of odd degree, respectively, in an undirected graph G = (V , E) with m edges. Then

2 m =

v ∈V

deg( v ) =

v ∈V 1

deg( v ) +

v ∈V 2

deg( v ).

Because deg( v ) is even for v ∈ V 1 , the first term in the right-hand side of the last equality is even. Furthermore, the sum of the two terms on the right-hand side of the last equality is even, because this sum is 2m. Hence, the second term in the sum is also even. Because all the terms in this sum are odd, there must be an even number of such terms. Thus, there are an even number of vertices of odd degree.

Terminology for graphs with directed edges reflects the fact that edges in directed graphs have directions.

654 10 / Graphs

DEFINITION 4 When (u, v ) is an edge of the graph G with directed edges, u is said to be adjacent to v and v

is said to be adjacent from u. The vertex u is called the initial vertex of (u, v ), and v is called the terminal or end vertex of (u, v ). The initial vertex and terminal vertex of a loop are the same.

Because the edges in graphs with directed edges are ordered pairs, the definition of the degree of a vertex can be refined to reflect the number of edges with this vertex as the initial vertex and as the terminal vertex.

DEFINITION 5 In a graph with directed edges the in-degree of a vertex v , denoted by deg−( v ), is the number

of edges with v as their terminal vertex. The out-degree of v , denoted by deg+( v ), is the number of edges with v as their initial vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.)

EXAMPLE 4 Find the in-degree and out-degree of each vertex in the graph G with directed edges shown in

Figure 2.

e d f

a b

c

G

FIGURE 2 The Directed Graph G.

Solution: The in-degrees in G are deg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3, and deg−(f ) = 0. The out-degrees are deg+(a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+(e) = 3, and deg+(f ) = 0. ▲

Because each edge has an initial vertex and a terminal vertex, the sum of the in-degrees and the sum of the out-degrees of all vertices in a graph with directed edges are the same. Both of these sums are the number of edges in the graph. This result is stated as Theorem 3.

THEOREM 3 Let G = (V , E) be a graph with directed edges. Then

v ∈V

deg−( v ) =

v ∈V

deg+( v ) = |E|.

There are many properties of a graph with directed edges that do not depend on the direction of its edges. Consequently, it is often useful to ignore these directions. The undirected graph that results from ignoring directions of edges is called the underlying undirected graph. A graph with directed edges and its underlying undirected graph have the same number of edges.

Some Special Simple Graphs

We will now introduce several classes of simple graphs. These graphs are often used as examples and arise in many applications.

656 10 / Graphs

Q 1 Q 2

0 1

00 01

10 11

Q 3

000 001

100 101

110 111

(^010 )

FIGURE 6 The n -cube Q (^) n , n = 1 , 2 , 3.

Bipartite Graphs

Sometimes a graph has the property that its vertex set can be divided into two disjoint subsets such that each edge connects a vertex in one of these subsets to a vertex in the other subset. For example, consider the graph representing marriages between men and women in a village, where each person is represented by a vertex and a marriage is represented by an edge. In this graph, each edge connects a vertex in the subset of vertices representing males and a vertex in the subset of vertices representing females. This leads us to Definition 5.

DEFINITION 6 A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint

sets V 1 and V 2 such that every edge in the graph connects a vertex in V 1 and a vertex in V 2 (so that no edge in G connects either two vertices in V 1 or two vertices in V 2 ). When this condition holds, we call the pair (V 1 , V 2 ) a bipartition of the vertex set V of G.

In Example 9 we will show that C 6 is bipartite, and in Example 10 we will show that K 3 is not bipartite.

EXAMPLE 9 C 6 is bipartite, as shown in Figure 7, because its vertex set can be partitioned into the two sets

V 1 = { v 1 , v 3 , v 5 } and V 2 = { v 2 , v 4 , v 6 }, and every edge of C 6 connects a vertex in V 1 and a vertex in V 2. ▲

EXAMPLE 10 K 3 is not bipartite. To verify this, note that if we divide the vertex set of K 3 into two disjoint

sets, one of the two sets must contain two vertices. If the graph were bipartite, these two vertices could not be connected by an edge, but in K 3 each vertex is connected to every other vertex by an edge. ▲

EXAMPLE 11 Are the graphs G and H displayed in Figure 8 bipartite?

V 1 V 2 v 1 v 3 v 5

v 2 v 4 v 6

FIGURE 7 Showing That C 6 Is Bipartite.

a b c

e d

f

g

G

a b

e d H

f c

FIGURE 8 The Undirected Graphs G and H.

10.2 Graph Terminology and Special Types of Graphs 657

Solution: Graph G is bipartite because its vertex set is the union of two disjoint sets, {a, b, d} and {c, e, f, g}, and each edge connects a vertex in one of these subsets to a vertex in the other subset. (Note that for G to be bipartite it is not necessary that every vertex in {a, b, d} be adjacent to every vertex in {c, e, f, g}. For instance, b and g are not adjacent.) Graph H is not bipartite because its vertex set cannot be partitioned into two subsets so that edges do not connect two vertices from the same subset. (The reader should verify this by considering the vertices a, b, and f .) ▲

Theorem 4 provides a useful criterion for determining whether a graph is bipartite.

THEOREM 4 A simple graph is bipartite if and only if it is possible to assign one of two different colors to

each vertex of the graph so that no two adjacent vertices are assigned the same color.

Proof: First, suppose that G = (V , E) is a bipartite simple graph. Then V = V 1 ∪ V 2 , where V 1 and V 2 are disjoint sets and every edge in E connects a vertex in V 1 and a vertex in V 2. If we assign one color to each vertex in V 1 and a second color to each vertex in V 2 , then no two adjacent vertices are assigned the same color. Now suppose that it is possible to assign colors to the vertices of the graph using just two colors so that no two adjacent vertices are assigned the same color. Let V 1 be the set of vertices assigned one color and V 2 be the set of vertices assigned the other color. Then, V 1 and V 2 are disjoint and V = V 1 ∪ V 2. Furthermore, every edge connects a vertex in V 1 and a vertex in V 2 because no two adjacent vertices are either both in V 1 or both in V 2. Consequently, G is bipartite.

We illustrate how Theorem 4 can be used to determine whether a graph is bipartite in Example 12.

EXAMPLE 12 Use Theorem 4 to determine whether the graphs in Example 11 are bipartite.

Solution: We first consider the graph G. We will try to assign one of two colors, say red and blue, to each vertex in G so that no edge in G connects a red vertex and a blue vertex. Without loss of generality we begin by arbitrarily assigning red to a. Then, we must assign blue to c, e, f , and g, because each of these vertices is adjacent to a. To avoid having an edge with two blue endpoints, we must assign red to all the vertices adjacent to either c, e, f , or g. This means that we must assign red to both b and d (and means that a must be assigned red, which it already has been). We have now assigned colors to all vertices, with a, b, and d red and c, e, f , and g blue. Checking all edges, we see that every edge connects a red vertex and a blue vertex. Hence, by Theorem 4 the graph G is bipartite. Next, we will try to assign either red or blue to each vertex in H so that no edge in H connects a red vertex and a blue vertex. Without loss of generality we arbitrarily assign red to a. Then, we must assign blue to b, e, and f , because each is adjacent to a. But this is not possible because e and f are adjacent, so both cannot be assigned blue. This argument shows that we cannot assign one of two colors to each of the vertices of H so that no adjacent vertices are assigned the same color. It follows by Theorem 4 that H is not bipartite. ▲

Theorem 4 is an example of a result in the part of graph theory known as graph colorings. Graph colorings is an important part of graph theory with important applications. We will study graph colorings further in Section 10.8. Another useful criterion for determining whether a graph is bipartite is based on the notion of a path, a topic we study in Section 10.4. A graph is bipartite if and only if it is not possible to start at a vertex and return to this vertex by traversing an odd number of distinct edges. We will make this notion more precise when we discuss paths and circuits in graphs in Section 10. (see Exercise 63 in that section).

10.2 Graph Terminology and Special Types of Graphs 659

Alvarez Berkowitz Chen Davis

requirements architecture implementation testing

Washington Xuan Ybarra Ziegler

requirements architecture implementation testing (a) (b)

FIGURE 10 Modeling the Jobs for Which Employees Have Been Trained.

impossible because there are only two employees, Xuan and Ziegler, who have been trained for at least one of the three jobs of requirements, implementation, and testing. Consequently, there is no way to assign three different employees to these three job so that each job is assigned an employee with the appropriate training. ▲

Finding an assignment of jobs to employees can be thought of as finding a matching in the graph model, where a matching M in a simple graph G = (V , E) is a subset of the set E of edges of the graph such that no two edges are incident with the same vertex. In other words, a matching is a subset of edges such that if {s, t} and {u, v } are distinct edges of the matching, then s, t, u, and v are distinct. A vertex that is the endpoint of an edge of a matching M is said to be matched in M; otherwise it is said to be unmatched. A maximum matching is a matching with the largest number of edges. We say that a matching M in a bipartite graph G = (V , E) with bipartition (V 1 , V 2 ) is a complete matching from V 1 to V 2 if every vertex in V 1 is the endpoint of an edge in the matching, or equivalently, if |M| = |V 1 |. For example, to assign jobs to employees so that the largest number of jobs are assigned employees, we seek a maximum matching in the graph that models employee capabilities. To assign employees to all jobs we seek a complete matching from the set of jobs to the set of employees. In Example 14, we found a complete matching from the set of jobs to the set of employees for Project 1, and this matching is a maximun matching, and we showed that no complete matching exists from the set of jobs to the employees for Project 2. We now give an example of how matchings can be used to model marriages.

EXAMPLE 15 Marriages on an Island Suppose that there are m men and n women on an island. Each person

has a list of members of the opposite gender acceptable as a spouse. We construct a bipartite graph G = (V 1 , V 2 ) where V 1 is the set of men and V 2 is the set of women so that there is an edge between a man and a woman if they find each other acceptable as a spouse. A matching in this graph consists of a set of edges, where each pair of endpoints of an edge is a husband-wife pair. A maximum matching is a largest possible set of married couples, and a complete matching of V 1 is a set of married couples where every man is married, but possibly not all women. ▲

NECESSARY AND SUFFICIENT CONDITIONS FOR COMPLETE MATCHINGS We now turn our attention to the question of determining whether a complete matching from V 1 to V 2 exists when (V 1 , V 2 ) is a bipartition of a bipartite graph G = (V , E). We will introduce a theorem that provides a set of necessary and sufficient conditions for the existence of a complete matching. This theorem was proved by Philip Hall in 1935.

Hall’s marriage theorem is an example of a theorem where obvious necessary conditions are sufficient too.

THEOREM 5 HALL’S MARRIAGE THEOREM The bipartite graph G = (V , E) with bipartition

(V 1 , V 2 ) has a complete matching from V 1 to V 2 if and only if |N(A)| ≥ |A| for all subsets A of V 1.

660 10 / Graphs

Proof: We first prove the only if part of the theorem. To do so, suppose that there is a complete matching M from V 1 to V 2. Then, if A ⊆ V 1 , for every vertex v ∈ A, there is an edge in M connecting v to a vertex in V 2. Consequently, there are at least as many vertices in V 2 that are neighbors of vertices in V 1 as there are vertices in V 1. It follows that |N(A)| ≥ |A|. To prove the if part of the theorem, the more difficult part, we need to show that if |N(A)| ≥ |A| for all A ⊆ V 1 , then there is a complete matching M from V 1 to V 2. We will use strong induction on |V 1 | to prove this.

Basis step: If |V 1 | = 1, then V 1 contains a single vertex v 0. Because |N({ v 0 })| ≥ |{ v 0 }| = 1, there is at least one edge connecting v 0 and a vertex w 0 ∈ V 2. Any such edge forms a complete matching from V 1 to V 2.

Inductive step: We first state the inductive hypothesis.

Inductive hypothesis: Let k be a positive integer. If G = (V , E) is a bipartite graph with bipar- tition (V 1 , V 2 ), and |V 1 | = j ≤ k, then there is a complete matching M from V 1 to V 2 whenever the condition that |N(A)| ≥ |A| for all A ⊆ V 1 is met. Now suppose that H = (W, F ) is a bipartite graph with bipartition (W 1 , W 2 ) and |W 1 | = k + 1. We will prove that the inductive holds using a proof by cases, using two case. Case (i) applies when for all integers j with 1 ≤ j ≤ k, the vertices in every set of j elements from W 1 are adjacent to at least j + 1 elements of W 2. Case (ii) applies when for some j with 1 ≤ j ≤ k there is a subset W 1 ′ of j vertices such that there are exactly j neighbors of these vertices in W 2. Because either Case (i) or Case (ii) holds, we need only consider these cases to complete the inductive step.

Case (i) : Suppose that for all integers j with 1 ≤ j ≤ k, the vertices in every subset of j elements from W 1 are adjacent to at least j + 1 elements of W 2. Then, we select a vertex v ∈ W 1 and an element w ∈ N({ v }), which must exist by our assumption that |N({ v }| ≥ |{ v }| = 1. We delete v and w and all edges incident to them from H. This produces a bipartite graph H ′^ with bipartition (W 1 − { v }, W 2 − { w }). Because |W 1 − { v }| = k, the inductive hypothesis tells us there is a complete matching from W 1 − { v } to W 2 − { w }. Adding the edge from v to w to this complete matching produces a complete matching from W 1 to W 2.

Case (ii) : Suppose that for some j with 1 ≤ j ≤ k, there is a subset W 1 ′ of j vertices such that there are exactly j neighbors of these vertices in W 2. Let W 2 ′ be the set of these neighbors. Then, by the inductive hypothesis there is a complete matching from W 1 ′ to W 2 ′. Remove these 2j vertices from W 1 and W 2 and all incident edges to produce a bipartite graph K with bipartition (W 1 − W 1 ′, W 2 − W 2 ′). We will show that the graph K satisfies the condition |N(A)| ≥ |A| for all subsets A of W 1 − W 1 ′. If not, there would be a subset of t vertices of W 1 − W 1 ′ where 1 ≤ t ≤ k + 1 − j such that the vertices in this subset have fewer than t vertices of W 2 − W 2 ′ as neighbors. Then, the set of j + t vertices of W 1 consisting of these t vertices together with the j vertices we removed from W 1 has fewer than j + t neighbors in W 2 , contradicting the hypothesis that |N(A)| ≥ |A| for all A ⊆ W 1.

PHILIP HALL (1904–1982) Philip Hall grew up in London, where his mother was a dressmaker. He won a scholarship for board school reserved for needy children, and later a scholarship to King’s College of Cambridge University. He received his bachelors degree in 1925. In 1926, unsure of his career goals, he took a civil service exam, but decided to continue his studies at Cambridge after failing. In 1927 Hall was elected to a fellowship at King’s College; soon after, he made his first important discovery in group theory. The results he proved are now known as Hall’s theorems. In 1933 he was appointed as a Lecturer at Cambridge, where he remained until 1941. During World War II he worked as a cryptographer at Bletchley Park breaking Italian and Japanese codes. At the end of the war, Hall returned to King’s College, and was soon promoted. In 1953 he was appointed to the Sadleirian Chair. His work during the 1950s proved to be extremely influential to the rapid development of group theory during the 1960s. Hall loved poetry and recited it beautifully in Italian and Japanese, as well as English. He was interested in art, music, and botany. He was quite shy and disliked large groups of people. Hall had an incredibly broad and varied knowledge, and was respected for his integrity, intellectual standards, and judgement. He was beloved by his students.