Professional Documents
Culture Documents
Directed Graph: Azlinajumadi Marchjune2018
Directed Graph: Azlinajumadi Marchjune2018
GRAPH
CHAPTER 4
AZLINAJUMADI MARCHJUNE2018
INTRODUCTION
• Graphs are a generalization of trees
– Nodes or vertices
– Edges or arcs
• Two kinds of graphs
– Directed
– Undirected Gemereh
Tebing Tinggi
Segamat Jementah
UiTM
CONCEPT OF A BASIC GRAPH
• Undirected Graph
a set of objects (called vertices or nodes) that are connected together,
where all the edges are bidirectional.
(sometimes called an undirected network)
E
• Loop
An edge incident on a single vertex
• Isolated Vertex
A vertex that is not incident on any edge
• Simple Graph
A graph with neither loops nor parallel edges
RELATIONS AND DIRECTED GRAPH
Given A and a relation R on the set A. We can construct a directed graph
G consisting of the vertices in set A and the edges in set E: A x A.
Example 1:
Draw a directed graph for the following relation, R.
a) R = {(1, 2), (1, 5), (2, 2), (5, 2), (5, 5)}
b) R = {(a, b), (a, c), (b, a), (b, d), (c, c), (c, d)}
RELATIONS AND DIRECTED GRAPH
PRORERTIES OF RELATION
Function,
Not 1-to- 1 Not Function
FUNCTIONS AND DIRECTED GRAPHS
Example 5:
Given f: A→B where f(a) = 2a and A = {2, 3, 4}, B = {4, 6, 8, 10}. Is f one-to-
one? Is f onto? Why?
1-to- 1
- only one arc going into
node 4, 8, and 6
Not onto
- No arc going into node 10
FUNCTIONS AND DIRECTED GRAPHS
CONNECTED GRAPH
A graph is connected if there is an edge that connects two nodes v and w, and
v ≠ w. In other words, a connected graph is a graph in which we can get from
one node to any other node on a path. There will be no isolated node.
Example 6:
Determine if the following graph is a connected graph or not.
a) b)
YES NO
FUNCTIONS AND DIRECTED GRAPHS
SUBGRAPH
• A subgraph S of a graph G is a graph whose set of vertices and set of edges
are all subsets of G.
• Since every set is a subset of itself, every graph is a subgraph of itself.
• All the edges and vertices of G might not be present in S
• If a vertex is present in S, it has a corresponding vertex in G
• Any edge that connects two vertices in S will also connect the corresponding
vertices in G.
FUNCTIONS AND DIRECTED GRAPHS
## SUBGRAPH
Example 7:
Let G be the graph given below.
Example 8:
Let G be the graph given below. Draw a subgraph G1=G \ {e} and G2=G \ {v}.
PATH IN DIRECTED GRAPH
• Degree
The number of edges incident on a node
• Size of graph
Number of vertices that are in the graph
• In degree
The number of arcs going into a node
• Out degree
The number of arcs going out from a node
• Distance of a path
Number of arcs that are visited. (distance = nodes – 1)
PATH IN DIRECTED GRAPH
• Path
Allows repetitions of vertices or edges or both
• Cycle/circuit
– No repeated edges (except for the beginning and ending vertices that are
both equal)
– Distance of cycle must at least 3
PATH IN DIRECTED GRAPH
(SIMPLE PATH VS ELEMENTARY PATH)
• Simple Path
A path with no repeated edges
• Elementary Path
A path that that has no repeated nodes
a–f–d–c–g–b–e
or
a–f–d–c–g–e–b
PATH IN DIRECTED GRAPH
• Hamiltonian Path
– A path that visits each node in the graph exactly one time
– may not pass through all the edges in the graph
• Hamiltonian Cycle
– A path that starts and ends at the same node, visits each node in the
graph exactly one time
– except for the initial node which is visited twice; at the beginning and
end of the cycle
PATH IN DIRECTED GRAPH
Example 11:
Given a graph G as below. Determine whether a Hamiltonian path and a
Hamiltonian circuit exist. If it exists, give an example of the path/circuit. If it
doesn’t, state the reason(s).
a) b) c)
Eulerian path exist. 3 – 2 – 1 – 3 – 4 – 1 – 5 – 4 Eulerian path not exist because the path not have exactly two
Eulerian circuit not exist because the path have odd odd degree vertices
degree vertices Eulerian circuit exist.
a–b–c–f–i–h–g–d–b–e–f–h–e–d–a
EXERCISES
1) Given a graph G as below.
a) From the graph above, determine whether a Hamiltonian path, a Hamiltonian circuit, an
Eulerian path and an Eulerian circuit exist. If it exists, give an example of the
path/circuit. If it doesn’t, state the reason(s).
b) Draw a subgraph G1=G\{b, e}.
EXERCISES
4) For the graph given below,
Example 13:
Determine if the following graph is a connected graph or not.
a) YES b) c) NO
NO
TREES
SPANNING TREE
• A spanning tree of a graph is a subgraph of G that contains all vertices of G
• A graph will have several spanning tree. Spanning trees are not unique.
• A spanning tree will have the least number of edges that connects all nodes
in the original graph.
• Example:
Example 15:
Based on Huffman Code given,
a) Decode 110000001000, 110011001101, 1000100111101
b) Encode FLEET, BELL, FLOUT
TREES
HUFFMAN CODE
• Example of binary tree
Example 18:
Based on Huffman Code given,
a) Decode 110000001000, 110011001101, 1000100111101
b) Encode FLEET, BELL, FLOUT
1) BOOT, BLUE, TUBE
2) 010011011011000, 11101001001, 0100100010011000
EXERCISES
• Given the following algebraic expression.
1)
a) 011000010
b) 01110100110
c) 01111001001110
d) 1110011101001111
PEN, LAP, DEAL, SALAD