8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
1/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 1 of 14
GraphsIntroduction
Undirected Graphs
• An undirected graph is a finiteset of points and linesconnecting the points.
• The points in a graph are callednodes or vert ices , and the lines
are called edges or arcs .
For example:
1
2 3
4 5
node
edge
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
2/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 2 of 14
• In this course, an undirected
graph will simply be called agraph.
• Each node in a graph is labeled
while each edge is identified
using a tuple (i , j ), where i and j are the nodes that the edge
connects.
For example:
Take note that edge (1, 3) can
also be referred to as edge (3,1).
1
2 3
4 5
edge
(1, 3)
edge(3, 5)
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
3/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 3 of 14
•
The number of edges connectedto a node is called the degree of
that node.
For example:
In this graph, node 1 has a
degree of 2 while node 4 has
a degree of 3.
No more than one edge is
allowed between any two nodes.
1
2 3
4 5
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
4/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 4 of 14
•
A graph G can be described asbeing composed by a set of
nodes, N , and a set of edges, E .
G = (N , E )
Examples:
G = ({1, 2, 3, 4, 5}, {(1, 2), (1, 3),
(2, 4), (3, 4), (3, 5), (4, 5)})
1
2 3
4 5
Graph G
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
5/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 5 of 14
H = ({1, 2, 3, 4, 5, 6}, {(1, 2),
(1, 3), (2, 6), (3, 4), (3, 5),
(4,5)})
1
2
3
6
5
4 Graph H
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
6/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 6 of 14
• A subgraph of graph G is a
graph whose set of nodes is asubset of that of G and whose
edges are the edges of G on the
corresponding nodes.
For example:
1
2
3
6
5
4
3 5
4
Subgraph of
Graph G
Graph G
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
7/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 7 of 14
• A path in a graph is a sequence
of consecutive edges.
A path is a s imple path if there
are no repeated nodes.
The length of a path is thenumber of edges within the path.
For example:
The length of the path indicated
is 3.
1
2
3
6
5
4
Path
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
8/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 8 of 14
•
If every two nodes in a graphhave a path between them, the
graph is called a connected
graph.
•
If there is at least two nodes in agraph that do not have a path
between them, then the graph is
called a disconnected graph .
For example:
1
2
3
6
5
4
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
9/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 9 of 14
• A path is a cyc le if it starts and
ends in the same node. Takenote that the choice of the
starting node is arbitrary.
A s imp le cyc le is a cycle that
contains at least three nodesand has no repeating nodes
except for the first and last node.
For example:
1
2
3
6
5
4
A path which
is a cycle
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
10/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 10 of 14
• A special kind of graph that is
connected and has no simple
cycles is called a tree .
For example:
1
2 3
54 6 7 8
9 10
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
11/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 11 of 14
Directed Graphs
• A directed graph is similar to an
undirected graph except that
edges are replaced by directed
edges .
In other words, lines are
replaced by arrows.
For example:
1
2
3
6
5
4
Directed GraphG
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
12/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 12 of 14
• An edge connecting two nodes
from node i to node j isrepresented as the ordered pair
(i , j ). While an edge connecting
two nodes from node j to node i
is represented as the ordered
pair ( j , i ).
Since these are ordered pairs,
edge (i , j ) is different from edge
( j , i ).
For example:
1
2
3
6
5
4
Edge (2, 6)
Edge (6, 2)
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
13/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 13 of 14
• The formal description of thegiven directed graph G would
then be:
G = ({1, 2, 3, 4, 5, 6}, {(1, 2),
(1, 3), (2, 6), (3, 1), (3, 4),
(4, 5), (5, 3), (6, 2)})
1
2
3
6
5
4
Directed Graph G
8/21/2019 MELJUN CORTES Automata Lecture Graphs 2
14/14
Graphs
Theory of Computation (With Automata Theory)
* Property of STI
Page 14 of 14
• In a directed graph, the number
of arrows pointing from a
particular node is the outdegree
of that node
The number of arrows pointing
to a particular node is the
indegree .
For example:
For the given directed graph
G, the outdegree of node 1 is
2 while its indegree is 1.