2. Basic Concepts
A graph is an ordered pair (V, E).
V is the set of vertices. (You can think of them as integers 1,
2, …, n.)
E is the set of edges. An edge is a pair of vertices: (u, v).
Edges can be labeled with a weight:
6-Graphs
10
3. Concepts: Directedness
In a directed graph, the edges are “one-way.” So an edge (u, v)
means you can go from u to v, but not vice versa.
In an undirected graph, there is no direction on the edges: you can go
either way. (Also, no self-loops.)
6-Graphs
a self-loop
4. Concepts: Adjacency
Two vertices are adjacent if there is an edge between them.
For a directed graph, u is adjacent to v iff there is an edge (v, u).
6-Graphs
u w
v
u is adjacent to v.
v is adjacent to u and w.
w is adjacent to v.
u w
v
u is adjacent to v.
v is adjacent to w.
5. Concepts: Degree
Undirected graph: The degree of a vertex is the number of edges
touching it.
For a directed graph, the in-degree is the number of edges entering
the vertex, and the out-degree is the number leaving it. The degree is
the in-degree + the out-degree.
6-Graphs
degree 4
in-degree 2, out-degree 1
6. Concepts: Path
A path is a sequence of adjacent vertices. The length of a path is the
number of edges it contains, i.e. one less than the number of vertices.
We write u ⇒ v if there is path from u to v. We say v is reachable
from u.
6-Graphs
1
2
3
4
Is there a path from 1 to 4?
What is its length?
What about from 4 to 1?
How many paths are there from 2 to
3? From 2 to 2? From 1 to 1?
7. Concepts: Cycle
•A cycle is a path of length at least 1 from a vertex to itself.
•A graph with no cycles is acyclic.
•A path with no cycles is a simple path.
•The path <2, 3, 4, 2> is a cycle.
6-Graphs
1
2
3
4
8. Concepts: Connectedness
•An undirected graph is connected iff there is a path between any two
vertices.
•The adjacency graph of U.S. states has three connected components.
Name them.
•(We say a directed graph is strongly connected iff there is a path
between any two vertices.)
6-Graphs
An unconnected graph with three
connected components.
13. ASSESSMENT
1. Which of the following statements is true?
A. A graph can drawn on paper in only one
way.
B. Graph vertices may be linked in any
manner.
C. A graph must have at least one vertex.
D. A graph must have at least one edge.
14. CONTD..
2. Suppose you have a game with 5 coins in
a row and each coin can be heads or tails.
What number of vertices might you expect to
find in the state graph?
A. 7
B. 10
C. 25
D. 32
15. CONTD..
3. Why is the state graph for tic-tac-toe a
directed graph rather than an undirected
graph?
A. Once a move is made, it cannot be
unmade.
B. There is an odd number of vertices.
C. There is an odd number of edges.
D. There is more than one player in the
game.
16. CONTD..
4. A simple graph has no loops. What other
property must a simple graph have?
A. It must be directed.
B. It must be undirected.
C. It must have at least one vertex.
D. It must have no multiple edges.
17. CONTD..
5. Suppose you have a directed graph
representing all the flights that an airline flies.
What algorithm might be used to find the best
sequence of connections from one city to
another?
A. Breadth first search.
B. Depth first search.
C. A cycle-finding algorithm.
D. A shortest-path algorithm.