Вы находитесь на странице: 1из 12

Faculty of Mathematics Centre for Education in

Waterloo, Ontario N2L 3G1 Mathematics and Computing

Grade 6 Math Circles


February 11/12, 2014
Graph Theory I
A B

C D
Source: http://world.mathigon.org/Graph_Theory

Consider the picture and graphical representation above. There are 5 islands and 8 bridges
connecting them. Can you find a way to cross all the bridges exactly once? You can start
and end anywhere, but remember that you must cross every bridge, and you cant cross the
same bridge more than once.

Terminology
A vertex (plural: vertices) is a point.

An edge is a line that joins two vertices.

Two vertices are adjacent if there is an edge joining them.

A vertex and edge are incident if they are joined.

A walk is a sequence of vertices where each vertex is adjacent to the vertex before and
after it.

Think about walking from one vertex to another (on edges) and keeping track of
all the vertices you pass on the way.

A path is a walk that doesnt repeat vertices.

A cycle is a path that begins and ends at the same vertex.

1
Notation
A vertex is usually labelled with a letter, number, or other title. (ex. A)

An edge is named in the format {, }, where is replaced by the vertices it is


incident to. (ex. {A, B})

A graph is usually named G unless it is special or well-known (we will see examples
of these in the problem set). To distinguish graphs, a subscript can be used. (ex. G1 )

A walk can be written as vertex, edge, vertex... or as vertex, vertex, vertex.... We


will use the vertex only notation (ex. A B E A C)

A path can be written in the same way as a walk. (ex. A B E C D)

Exercise 1 a

b c

d f
e
G
1. Use the graph above to answer the following questions

(a) List the vertices in G. a, b, c, d, e, f


(b) List the edges in G. {a,b},{b,d},{a,c},{c,f},{d,e},{e,f},{b,e},{c,e},{a,e},{b,c}
(c) What is the difference between the terms incident and adjacent? Incident is
used when talking about an edge and a vertex. Adjacent is used when talking
about two vertices.
(d) Vertex a is adjacent to vertex e.
(e) Vertex d is incident to edge {d, e}.
(f) Create a walk from b to f . Answers will vary. Example: b,e,f
(g) Is your walk from part (f) also a path? If not, find one that is and explain why it
is a path. If it is already a path, explain why and find a walk that isnt a path.
Answers will vary. A path should have no repeating vertices.
(h) Find a cycle in G. Answers will vary. Example: a,b,e,c,a

2
Rules
These are the rules that we will be using. Different types of graphs and different parts of
graph theory have different rules.
1
1

6
5
2 3

4
2
6
4 3
5
G1 G2

Edges can be curved or straight (or any other shape).

Edges can cross.

The placement of vertices doesnt matter. Only the connections are important.

For example, G1 is the same as G2 since all the connections are the same.

Two edges cant connect the same vertices. (ie. There can only be a maximum of
one edge between any two vertices.)

An edge can not connect a vertex to itself.

Edges have no direction.

Exercise 2

1. Draw a graph that breaks some (or all) of these rules. Exchange graphs with a partner
and try to find all the violations. Redraw the graph so it follows all the rules. Answers
will vary.

3
Connectedness
1
A B
7 2 4
8
6
D
C
3
E 9
5
10
G3 G4
A graph is connected if all the vertices are joined together (either directly or through
other vertices). G3 is connected.
A graph is not connected if you can find two vertices that are not joined together
(either directly or through other vertices). G4 is not connected.

A component is a group of connected vertices. For example, G3 has 1 component,


but G4 has 2 components.

A bridge is an edge that joins two components into one. In other words, when a bridge
is removed 1 component is split into 2.

Exercise 3
1
a d
2

4 c e f
3 b

G5 5 G6

(a) Is G5 connected? What about G6 ? Yes, both are connected.

(b) How many bridges does G5 have? What about G6 ? G5 has no bridges. G6 has 1 bridge

(c) If you remove all bridges are G5 and G6 still connected? G5 is still connected since it
didnt have any bridges. G6 is not connected after the bridge is removed.

(d) If you remove all bridges how many components are there? G5 has 1 component. G6
has 2 components.

4
Trees
A F

B C E D

D E C
B
F T1 A
T2
A tree is a graph that doesnt contain any cycles (and is connected). For example, T1 and
T2 are trees. Although edges dont have any direction, think of trees as starting from the
top (or bottom depending on how it is drawn) and going down (or up). T1 starts from the
top while T2 starts from the bottom. We will focus on trees starting from the top like T1 .
Trees usually start with one vertex and branch out. The vertex it starts with is called the
root. In T1 , A is the root. Notice that any vertex can be the root depending on how it is
drawn. The vertices at the bottom of the tree that only have one edge connected to them
are called leaves. A group of trees is called a forest.

Exercise 4
1. Redraw T1 from above with B as the root.

2. Use the graph below for the following questions (remember that this is all one graph):

(a) Draw a triangle around every root. How many roots are there?
(b) Draw a heart around each leaf. How many leaves are there?
(c) Draw a square around every tree. How many trees are there?
(d) Circle the largest forest.

5
Breadth-First Search Trees (BFST)
A Breadth-First Search Tree or BFST is a way to make a tree from any graph. This
allows us to easily find vertices and shortest paths.

Important: A BFST can not replace a graph since there are edges missing.

T3 is an example of a BFST created from G7 .

e
b a level 0
c
d g
level 1
g f
c e b f
d level 2
a
G7 T3
In BFSTs, each row of vertices is on a different level. The root of the tree is on level 0.
Mathematically, we write level(a) = 0.
First we will look at the full BFST algorithm. We will look at a short-cut after.

BFST Algorithm:

1. Draw the first vertex and put it in the queue. (You will usually be told which vertex
to start with).

The queue is a line-up for the vertices. Always add vertices to the back of the
queue.

2. Draw the vertices that are connected to it. To make it easier to compare answers, we
will write the vertices in order. Put each vertex in the queue as you draw it. Remove
the vertex you started with from the queue.

3. Draw the vertices that are connected to the next vertex in the queue. Do not draw
or connect to any vertices that are already drawn. Remember to add every vertex to
the queue as you draw it.

4. Continue doing this until there are no vertices left in the queue.

6
Example of BFST Algorithm

e
b
c

g f
d
a
G7

Create a BFST from G7 starting at a and queuing the vertices in alphabetical order.

1. Draw vertex a and add it to the queue. Queue: a

2. g and d are adjacent to a. Since d comes before g in the alphabet, draw vertex d and
add it to the queue. Draw vertex g and add it to the queue. Remove a from the queue.
Queue: d g

3. Since d is next in the queue, look at the vertices adjacent to it. d is adjacent to a, e,
and c. a is already in the tree, so we can ignore it. c comes before e in the alphabet
so draw c, add it to the queue, draw e and add it to the queue. Remove d from the
queue. Queue: g c e

4. g is adjacent to e, b, a, and f , but a and e are already in the tree. Draw b and f , add
them to the queue, and remove g from the queue. Queue: c e b f

5. c is adjacent to b, e, and d. All these vertices are already in the tree, so we remove c
from the queue without adding anything to the tree or the queue. Queue: e b f

6. e is adjacent to c, b, g and d. All these vertices are already in the tree, so we remove
e from the queue without adding anything to the tree or the queue. Queue: b f

7. b is adjacent to c, e, f and g. All these vertices are already in the tree, so we remove
b from the queue without adding anything to the tree or the queue. Queue: f

8. f is adjacent to g, and b. All these vertices are already in the tree, so we remove f
from the queue without adding anything to the tree or the queue. Queue: empty

9. The queue is empty so the tree is complete.

7
BFST Short-cut:
1. Draw the first vertex. (You will usually be told which vertex to start with).
2. Draw the vertices that are connected to it. To make it easier to compare answers, we
will write the vertices in order.
3. Draw the vertices that are connected to the first vertex. Do not draw or connect to
any vertices that are already drawn.
4. Continue doing this until you can not add any more vertices.
The trick with the short-cut is to move from left to right on one level. Once you get to the
end of a level, move to the left-most vertex in the next level.

Example of BFST Short-cut


e
b
c

g f
d
a
G7
Create a BFST from G7 starting at a and queuing the vertices in alphabetical order.
1. Draw vertex a.
2. a is adjacent to g and d, so add them to the tree.
3. Start with d since it comes first in the alphabet. d is adjacent to a, e, and c. a is
already in the tree, so add e and c to the tree.
4. Moving right from d, but staying on the same level, we look at vertex g. g is adjacent
to e, b, a, and f , but a and e are already in the tree. Draw b and f .
5. Since there are no more vertices on this level, we move to the left-most vertex in the
next level: c. c is adjacent to e, b, and d. All these vertices are in the tree so move on
to the next vertex.
6. e is adjacent to c, b, g and d. All these vertices are already in the tree, so move on to
the next vertex.
7. b is adjacent to c, e, f and g. All these vertices are already in the tree, so move on to
the next vertex.
8. f is adjacent to g, and b. All these vertices are already in the tree, so move on to the
next vertex.
9. There are no more vertices in this level and there are no more levels, so the tree is
complete.

8
Problem Set
* indicates challenge question

1. Trace the following walks on the graph below. For each one, state whether it is a path?
How do you know?

(a) L-C-E-A-B-A-D (b) H-F-G-J-D-A

A A
B K B K
E D E D

F J F J
L L
G G
C C
I I
H H
(c) F-D-A-B-K-E-A (d) F-G-J-H

A A
B K B K
E D E D

F J F J
L L
G G
C C
I I
H H
(e) D-A-E-B-K-E-C

A
B K
E D

F J
L
G
C
I
H

9
2. Find 10 walks from 1 to 4 in the following graph. How many of these walks are paths?
How many possible paths are there between 1 and 4. (Hint: You may want to redraw
the graph)
4

1
3
9
2 10
6 11
5
8
7

3. Find all the cycles in the following graph.


1 2

4 5 6

9
8

4. A complete graph is a graph that has all possible edges. This means that every
vertex is connected to every other vertex. We name a graph of this type Kn where n
is the number of vertices.K5 is an example of this type of graph. Which edges should
be added to the graph below to make it K5 ? Write the names of the edges and then
draw them on the graph.
a

e b

d c

10
5. A k-regular graph is a graph with k edges incident
j
to each vertex. An example of this is the Petersen
Graph which is a type of 3-regular graph. a
i g
Luc, Ryan, Vince, Emily, and Nadine go to a party. e b
When they get there they want to shake hands but
they only have time to shake two other peoples
d c
hands. Draw two different graphs to show how this
can happen. How many handshakes are there? Do f h
the rules for drawing a graph make sense in this sit-
Petersen Graph
uation?

6. *Is a vertex always on the same level if the BFST is created with a different root?

7. *The length of a path is the number of edges in the path. For example, for a path
1-2-3-4, the length would be 3. The shortest path is the path with the least number
of edges possible. What does the level of a vertex in a BFST tell you about the
relationship between the root and a vertex?

8. *How can you use a BFST to determine the shortest path between two vertices?

9. **Explain why a BFST gives the shortest path between the root and any other vertex.
(Hint: think about where the vertex would be if there was a shorter path)

10. **Does rearranging a BFST create another valid BFST? Either explain why it does or
show that it doesnt by creating a BFST and rearranging it. (Hint: think about the
order vertices are drawn on the tree. Would it change if you started with a different
root?)

11. Find a shortest path between 1 and 4. Check your answer by drawing a BFST.
3
2
9
5
8 1

10
4
6 7

11
12. Below is a graph of colours from an imaginary world. An edge between two vertices
means that you can create those colours from each other. What is the fastest way to
create yellow if you are starting with green? Use a BFST to solve.
blue

purple
yellow
red

orange

teal

pink green

13. Sarah has a letter that she wants to give to Emily. But they wont see each other
because they are in different cities. Below is a map of people who will see each other.
Use a BFST to find the quickest way for Sarah to get the letter to Emily and then
answer the questions. Sarah
Kamil
Tim
Ishi Ryan Vince

Lawren
Luc
Cass Dalton
Nadine
Emily

(a) Which people must see each other in order for Sarah to get the letter to Emily?
In other words, if these people dont meet then it is impossible for Sarah to get
the letter to Emily.
(b) What do these vertices have in common?
(c) If Ryan and Vince dont meet, what changes about the graph (other than removing
an edge)?
(d) Vince lives far from Sarah so she doesnt want to give him the letter. What is the
fastest way now?
(e) Dalton has a letter that he wants to give to Ishi. What is the fastest way for him
to do this?

12

Вам также может понравиться