COM555 Theory of Computation: Graphs
COM555 Theory of Computation: Graphs
Theory of Computation
Lecture 3
Graphs
All nodes 3 4
5 2 have
degree 2
3 4
5 2
1 2
3 4
1 2 What is indegree of
node 1? Two
What is outdegree of
6 3 node 3? Zero
What is outdegree of
node 5? Two
5 4 What is indegree of
node 6? One
SubGraphs
• Subgraph G is a subgraph of H if the nodes of
G are a subset of the nodes of H, and edges of
G are the edges of H on the corresponding
nodes. H=({1,2,3,4,5},{(1,4),(1,5),
1 (2,1),(2,3),(3,1), (3,4),(5,2),
3 (5,4)})
2 G=({1,2,3,4},{(1,4),(2,1),
4 (3,1),(3,4)})
5
Path
• A path in a graph is a sequence of nodes
connected by edges.
– A path between the nodes 2-3-4
– Or a path between the nodes 1-5-2
1
3
2
4
5
Cycle
• A path is a cycle if it starts and ends in the
same node.
• A simple cycle contains at least three nodes
and repeats only the first and the last nodes.
1 1
3 3
2 2
4 4
5 5
Cycle 1-5-2-1 Cycle 2-1-3-4-5-2
Connected Graphs
• A graph is connected if every two nodes have
a path between them
1 1
3 3
2 2
4 4
5 5
Connected graph Disconnected graph
Trees
• A graph is a tree if it is connected and has no
simple cycles.
1
2 5 3
7 4 6
8 9 Connected and no
simple cycles