0% found this document useful (0 votes)
25 views

Planar Graph and Trees

Planar graph and tree discrete math
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Planar Graph and Trees

Planar graph and tree discrete math
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Planar Graph:

A graph is said to be planar if it can be drawn in a plane so that no edge cross.


Example: The graph shown in fig is planar graph.

Region of a Graph: Consider a planar graph G=(V,E).A region is defined to be an area of the plane
that is bounded by edges and cannot be further subdivided. A planar graph divides the plans into one
or more regions. One of these regions will be infinite.
Finite Region: If the area of the region is finite, then that region is called a finite region.
Infinite Region: If the area of the region is infinite, that region is called a infinite region. A planar
graph has only one infinite region.
Example: Consider the graph shown in Fig. Determine the number of regions, finite regions and an
infinite region.

1
Solution: There are five regions in the above graph, i.e. r1,r2,r3,r4,r5.
There are four finite regions in the graph, i.e., r2,r3,r4,r5.
There is only one finite region, i.e., r1
Properties of Planar Graphs:

1. If a connected planar graph G has e edges and r regions, then r ≤ e.


2. If a connected planar graph G has e edges, v vertices, and r regions, then v-e+r=2.
3. If a connected planar graph G has e edges and v vertices, then 3v-e≥6.
4. A complete graph Kn is a planar if and only if n<5.
5. A complete bipartite graph Kmn is planar if and only if m<3 or n>3.
Example: Prove that complete graph K4 is planar.
Solution: The complete graph K4 contains 4 vertices and 6 edges.
We know that for a connected planar graph 3v-e≥6.Hence for K4, we have 3x4-6=6 which satisfies
the property (3).
Thus K4 is a planar graph. Hence Proved.
Non-Planar Graph:
A graph is said to be non planar if it cannot be drawn in a plane so that no edge cross.
Example: The graphs shown in fig are non planar graphs.

2
These graphs cannot be drawn in a plane so that no edges cross hence they are non-planar graphs.
Properties of Non-Planar Graphs:
A graph is non-planar if and only if it contains a subgraph homeomorphic to K5 or K3,3
Example1: Show that K5 is non-planar.
Solution: The complete graph K5 contains 5 vertices and 10 edges.
Now, for a connected planar graph 3v-e≥6.
Hence, for K5, we have 3 x 5-10=5 (which does not satisfy property 3 because it must be greater than
or equal to 6).
Thus, K5 is a non-planar graph.
Example2: Show that the graphs shown in fig are non-planar by finding a subgraph homeomorphic
to K5 or K3,3.

Solution: If we remove the edges (V1,V4),(V3,V4)and (V5,V4) the graph G1,becomes homeomorphic
to K5.Hence it is non-planar.
If we remove the edge V2,V7) the graph G2 becomes homeomorphic to K3,3.Hence it is a non-planar.
Graph Coloring:

3
Suppose that G= (V,E) is a graph with no multiple edges. A vertex coloring of G is an assignment of
colors to the vertices of G such that adjacent vertices have different colors. A graph G is M-Colorable
if there exists a coloring of G which uses M-Colors.
Proper Coloring: A coloring is proper if any two adjacent vertices u and v have different colors
otherwise it is called improper coloring.
Example: Consider the following graph and color C={r, w, b, y}.Color the graph properly using all
colors or fewer colors.

The graph shown in fig is a minimum 3-colorable, hence x(G)=3


Solution: Fig shows the graph properly colored with all the four colors.

Fig shows the graph properly colored with three colors.

4
Chromatic number of G: The minimum number of colors needed to produce a proper coloring of a
graph G is called the chromatic number of G and is denoted by x(G).
Example: The chromatic number of Kn is n.
Solution: A coloring of Kn can be constructed using n colours by assigning different colors to each
vertex. No two vertices can be assigned the same colors, since every two vertices of this graph are
adjacent. Hence the chromatic number of Kn=n.
Applications of Graph Coloring
Some applications of graph coloring include:
o Register Allocation
o Map Coloring
o Bipartite Graph Checking
o Mobile Radio Frequency Assignment
o Making a time table, etc.
State and prove Handshaking Theorem.

Handshaking Theorem: The sum of degrees of all the vertices in a graph G is equal to twice the
number of edges in the graph.
Mathematically it can be stated as:
∑v∈Vdeg(v)=2e
Proof: Let G = (V, E) be a graph where V = {v1,v2, . . . . . . . . . .} be the set of vertices and E =
{e1,e2 . . . . . . . . . .} be the set of edges. We know that every edge lies between two vertices so it
provides degree one to each vertex. Hence each edge contributes degree two for the graph. So the
sum of degrees of all vertices is equal to twice the number of edges in G.
Hence, ∑v∈Vdeg(v)=2e

General Trees
A graph which has no cycle is called an acyclic graph. A tree is an acyclic graph or graph having no
cycles.
A tree or general trees is defined as a non-empty finite set of elements called vertices or nodes having
the property that each node can have minimum degree 1 and maximum degree n. It can be partitioned
into n+1 disjoint subsets such that the first subset contains the root of the tree and remaining n subsets
includes the elements of the n subtree.

5
Directed Trees:
A directed tree is an acyclic directed graph. It has one node with indegree 1, while all other nodes
have indegree 1 as shown in fig:

The node which has outdegree 0 is called an external node or a terminal node or a leaf. The nodes
which have outdegree greater than or equal to one are called internal node.

6
Ordered Trees:
If in a tree at each level, an ordering is defined, then such a tree is called an ordered tree.
Example: The trees shown in the figures represent the same tree but have different orders.

Properties of Trees:
1. There is only one path between each pair of vertices of a tree.
2. If a graph G there is one and only one path between each pair of vertices G is a tree.
3. A tree T with n vertices has n-1 edges.
4. A graph is a tree if and only if it a minimal connected.
Rooted Trees:
If a directed tree has exactly one node or vertex called root whose incoming degrees is 0 and all other
vertices have incoming degree one, then the tree is called rooted tree.
Note: 1. A tree with no nodes is a rooted tree (the empty tree)
2. A single node with no children is a rooted tree.

7
Path length of a Vertex:
The path length of a vertex in a rooted tree is defined to be the number of edges in the path from the
root to the vertex.
Example: Find the path lengths of the nodes b, f, l, q as shown in fig:

Solution: The path length of node b is one.


The path length of node f is two.
The path length of node l is three
The path length of the node q is four.

Binary Trees:
If the outdegree of every node is less than or equal to 2, in a directed tree than the tree is called a
binary tree. A tree consisting of the nodes (empty tree) is also a binary tree. A binary tree is shown in
fig:

Basic Terminology:
Root: A binary tree has a unique node called the root of the tree.
Left Child: The node to the left of the root is called its left child.
Right Child: The node to the right of the root is called its right child.
Backward Skip 10sPlay VideoForward Skip 10s
Parent: A node having a left child or right child or both are called the parent of the nodes.
Siblings: Two nodes having the same parent are called siblings.
Leaf: A node with no children is called a leaf. The number of leaves in a binary tree can vary from
one (minimum) to half the number of vertices (maximum) in a tree.
Descendant: A node is called descendant of another node if it is the child of the node or child of
some other descendant of that node. All the nodes in the tree are descendants of the root.
Left Subtree: The subtree whose root is the left child of some node is called the left subtree of that
node.

Example: For the tree as shown in fig:

8
o Which node is the root?
o Which nodes are leaves?
o Name the parent node of each node

Solution: (i) The node A is the root node.


(ii) The nodes G, H, I, L, M, N, O are leaves.
(iii) Nodes Parent
B, C A
D, E B
F C
G, H D
I, J E
K F
L, M J
N, O K
Right Subtree: The subtree whose root is the right child of some node is called the right subtree of
that node.
Level of a Node: The level of a node is its distance from the root. The level of root is defined as zero.
The level of all other nodes is one more than its parent node. The maximum number of nodes at any
level N is 2N.
Depth or Height of a tree: The depth or height of a tree is defined as the maximum number of nodes
in a branch of a tree. This is more than the maximum level of the tree, i.e., the depth of root is one.
The maximum number of nodes in a binary tree of depth d is 2d-1, where d ≥1.
External Nodes: The nodes which have no children are called external nodes or terminal nodes.
Internal Nodes: The nodes which have one or more than one children are called internal nodes or
non-terminal nodes.

Binary Expression Trees:


An algebraic expression can be conveniently expressed by its expression tree. An expression having
binary operators can be decomposed into
<left operand or expression> (operator) <right operand or expression>
Depending upon precedence of evaluation.
The expression tree is a binary tree whose root contains the operator and whose left subtree contains
the left expression, and right subtree contains the right expression.
Example: Construct the binary expression tree for the expression (a+b)*(d/c)

9
Solution: The binary expression tree for the expression (a+b)*(d/c) is shown in fig:

Complete Binary Tree: Complete binary tree is a binary tree if it is all levels, except possibly the
last, have the maximum number of possible nodes as for left as possible. The depth of the complete
binary tree having n nodes is log2 n+1.
Example: The tree shown in fig is a complete binary tree.

10
Full Binary Tree: Full binary tree is a binary tree in which all the leaves are on the same level and
every non-leaf node has two children.

Differentiate between General Tree and Binary Tree


General Tree Binary Tree

1. There is no such tree having 1. There may be an empty binary tree.


zero nodes or an empty general
tree.

2. If some node has a child, then 2. If some node has a child, then it is distinguished as a
there is no such distinction. left child or a right child.

3. The trees shown in fig are the 3. The trees shown in fig are distinct, when we consider
same, when we consider them as them as binary trees, because in (4) is the right child of 2
general trees. while in (ii) 4 is a left child of 2.

11
Traversing Binary Trees
Traversing means to visit all the nodes of the tree. There are three standard methods to traverse the
binary trees. These are as follows:
1. Preorder Traversal
2. Postorder Traversal
3. Inorder Traversal
1. Preorder Traversal: The preorder traversal of a binary tree is a recursive process. The preorder
traversal of a tree is
o Visit the root of the tree.
o Traverse the left subtree in preorder.
o Traverse the right subtree in preorder.
2. Postorder Traversal: The postorder traversal of a binary tree is a recursive process. The postorder
traversal of a tree is
o Traverse the left subtree in postorder.
o Traverse the right subtree in postorder.
o Visit the root of the tree.
3. Inorder Traversal: The inorder traversal of a binary tree is a recursive process. The inorder
traversal of a tree is
o Traverse in inorder the left subtree.
o Visit the root of the tree.
o Traverse in inorder the right subtree.
Example: Determine the preorder, postorder and inorder traversal of the binary tree as shown in fig:

Solution: The preorder, postorder and inorder traversal of the tree is as follows:
Preorder 1 2 3 4 5 6 7 8 9 10 11

Postorder 3 5 4 2 7 10 9 11 8 6 1

Inorder 3 2 5 4 1 7 6 9 10 8 11

Algorithms:
(a)Algorithm to draw a Unique Binary Tree when Inorder and Preorder Traversal of the tree is
Given:
1. We know that the root of the binary tree is the first node in its preorder. Draw the root of the
tree.
2. To find the left child of the root node, first, use the inorder traversal to find the nodes in the
left subtree of the binary tree. (All the nodes that are left to the root node in the inorder

12
traversal are the nodes of the left subtree). After that, the left child of the root is obtained by
selecting the first node in the preorder traversal of the left subtree. Draw the left child.
3. In the same way, use the inorder traversal to find the nodes in the right subtree of the binary
tree. Then the right child is obtained by selecting the first node in the preorder traversal of the
right subtree. Draw the right child.
4. Repeat the steps 2 and 3 with each new node until every node is not visited in the preorder.
Finally, we obtain a unique tree.
Example: Draw the unique binary tree when the inorder and preorder traversal is given as follows:
Inorder B A D C F E J H K G I

Preorder A B C D E F G H J K I
Solution: We know that the root of the binary tree is the first node in preorder traversal. Now, check
A, in the inorder traversal, all the nodes that are of left A, are nodes of left subtree and all the nodes
that are right of A, are nodes of right subtree. Read the next node in the preorder and check its
position against the root node, if its left of the root node, then draw it as a left child, otherwise draw it
a right child. Repeat the above process for each new node until all the nodes of the preorder traversal
are read and finally we obtain the binary tree as shown in fig:

(b) Algorithm to draw a Unique Binary Tree when Inorder and Postorder Traversal of the tree
is Given:
1. We know that the root of the binary tree is the last node in its postorder. Draw the root of the
tree.
2. To find the right child of the root node, first, use the inorder traversal to find the nodes in the
right subtree of the binary tree. (All the nodes that are right to the root node in the inorder
traversal are the nodes of the right subtree). After that, the right child of the root is obtained
by selecting the last node in the postorder traversal of the right subtree. Draw the right child.
3. In the same way, use the inorder traversal to find the nodes in the left subtree of the binary
tree. Then the left child is obtained by selecting the last node in the postorder traversal of the
left subtree. Draw the left child.
4. Repeat the steps 2 and 3 with each new node until every node is not visited in the postorder.
After visiting the last node, we obtain a unique tree.

13
Example: Draw the unique binary tree for the given Inorder and Postorder traversal is given as
follows:
Inorder 4 6 10 12 8 2 1 5 7 11 13 9 3
Postorder 12 10 8 6 4 2 13 11 9 7 5 3 1

Solution: We know that the root of the binary tree is the last node in the postorder traversal. Hence,
one in the root node.
Now, check the inorder traversal, we know that root is at the center, hence all the nodes that are left to
the root node in inorder traversal are the nodes of left subtree and, all that are right to the root node
are the nodes of the right subtree.
Now, visit the next node from back in postorder traversal and check its position in inorder
traversal, if it is on the left of root then draw it as left child and if it is on the right, then draw it as the
right child.
Repeat the above process for each new node, and we obtain the binary tree as shown in fig:

(c)Algorithm to convert General Tree into the binary tree


1. Starting from the root node, the root of the tree is also the root of the binary tree.
2. The first child C1(from left) of the root node in the tree is the left child C1 of the root node in
the binary tree, and the sibling of the C1 is the right child of C1 and so on.
3. Repeat the step2 for each new node.
Example: Convert the following tree as shown in fig into a binary tree.

Solution: The root of the tree is the root of the binary tree. Hence A is the root of the binary tree.
Now B becomes the left child of A in a binary tree, C becomes the right child of B, D becomes right
child of C, and E becomes the right child of D in the binary tree and similarly applying the algorithm
we obtain the binary tree as shown in fig:

14
Binary Search Trees
Binary search trees have the property that the node to the left contains a smaller value than the node
pointing to it and the node to the right contains a larger value than the node pointing to it.
It is not necessary that a node in a 'Binary Search Tree' point to the nodes whose value immediately
precede and follow it.
Example: The tree shown in fig is a binary search tree.

Inserting into a Binary Search Tree: Consider a binary tree T. Suppose we have given an ITEM of
information to insert in T. The ITEM is inserted as a leaf in the tree. The following steps explain a
procedure to insert an ITEM in the binary search tree T.
1. Compare the ITEM with the root node.
2. If ITEM>ROOT NODE, proceed to the right child, and it becomes a root node for the right
subtree.
3. If ITEM<ROOT NODE, proceed to the left child.
4. Repeat the above steps until we meet a node which has no left and right subtree.
5. Now if the ITEM is greater than the node, then the ITEM is inserted as the right child, and if
the ITEM is less than the node, then the ITEM is inserted as the left child.
Example: Show the binary search tree after inserting 3, 1,4,6,9,2,5,7 into an initially empty binary
search tree.
Solution: The insertion of the above nodes in the empty binary search tree is shown in fig:

Deletion in a Binary Search Tree: Consider a binary tree T. Suppose we want to delete a given
ITEM from binary search tree. To delete an ITEM from a binary search tree we have three cases,
depending upon the number of children of the deleted node.
1. Deleted Node has no children: Deleting a node which has no children is very simple, as
replace the node with null.
2. Deleted Node has Only one child: Replace the value of a deleted node with the only child.
3. Deletion node has only two children: In this case, replace the deleted node with the node
that is closest in the value to the deleted node. To find the nearest value, we move once to the

15
left and then to the right as far as possible. This node is called the immediate predecessor.
Now replace the value of the deleted node with the immediate predecessor and then delete the
replaced node by using case1 or case2.
Example: Show that the binary tree shown in fig (viii) after deleting the root node.
Solution: To delete the root node, first replace the root node with the closest elements of the root. For
this, first, move one step left and then to the right as far as possible to the node. Then delete the
replaced node. The tree after deletion shown in fig:

16

You might also like