v.lavanya
MSC I T
OBJECTIVES
root node is desigated wich has no parent
if the imediate predecessor of the node is parent of the node then all imediate sucessor of a node
are known as child
child which is on left side is called left child and hat on right side is called
right child
Basic terminolgies
BINARY TREES WITH EXAMPLES
PROPERTIES OF BINARY TREE
 the maximum no of nodes
possible in a binary tree of
height h is 2power of h-1
The minimum no of nodes
possible in a binary tree Height
h is h
a binary tree has the minimum
no of nodes one every parent
has one child such kind of
trees are called skew binary
trees
LINEAR ARRAY
NONLINEAR
LINKED LIST
• The root N of T is stored
in TREE [1]. If a node
occupies TREE [k] then its
is stored in TREE
and its is
stored into TREE
Advantage of sequential rpresentation
any node can acessed from any other node by calculating the
index value
data are stored without any pointers to their
which are mentioned implicity
programing lanuage where dynamic memmory allocation is not
possible such as(BASIC ,FORTRAIN)ARRAY
REPREPRESENTAION IS nly means to store a tree
Disadvantage of sequential reprentation
other then the full of binary trees the majority of the array entries
may be empty
it allows only static representation it is in no way possible to
enhance the tree structure if the array size will be limited
insering new node to the tree or deleting a node in a tree data
moved up and moved down in an array excessive amount of
processing time
linked list representation
of a binary tree they are two field s
to stor the address of left child
and right child of the node
data is the current
information of the node
if one knows the address of the root node
then form it other node can be acessed
physical implementation of a binary tree in memmory
Algorithm build a tree
input:ITEM is the data contet of the node i
output: a binary tree with two sub-trees of the node i
data structure: array representation of a binary tree
operations of binary trees
 insertion: TO include a node into an existing binary tree
deletion: TO delete a node from a non-empty binary tree
Traversal: TO visit all the nodes in abinary tree
in traversal they are three orders
inorder -> LEFT->ROOT->RIGHT
preorder -> ROOT->LEFT->RIGHT
postorder-> LEFT->RIGHT->ROOT
merge:TO merge two binary trees into a large one
in this operation to insert a
new node at any position in
a binary tree
we have a simple insertion
for ex to insert a “g “ a new
node
two stops
search the existence node
second establish the link
insert a binary tree using linked list
• insert:KEY is the data content of the key node after new node is
to be inserted an ITEM is the data content of the new node can
be inserted
• output: A node with data component ITEM inserted as an
extrernal node after the node having data KEY if such a node
does not exist with empty (s), that is, eiter child or both children
IS/ARE ABSENT.
• DATA STRUCTURE: linked structure of a binary tree. ROOT is
the pointer to the root node.
algorithm
• PRINT “ insertion is not possible as left child”
• EXIT
• EDIF
• ELSE
• IF(pf->RC =NULL)
• new=GETNODE
• new->DATA=ITEM
• new->LC=new->RC=NULL
• ptr->RC=new
• else
• print”insertion is not possibble as right child”
• exit
• end if
• else
• print”the key node is already has a child”
• stop
deletion
• in deletion operation can be carried out of two kinds of storage
representation of binary trees
• in ordernto delete a node in a binary tree it is required to reach at
the parent node to be deleted
• the link of the parent nodes whih stores the location of the node
to be deleted is then set buy a NULL entry
• input:given ITEM as data of the node with which the node can be
identified for deletion
• output:a binary tree without a node having a data ITEM
• data stucture: array a storing binary trees SIZE denotes the size
of a
WHAT IS A TRAVERSAL?
THE traversal operation is frequently used operation of a binary
this operation to visit each node in the tree exactly once
a full traversal of a binary tree gives a linear ordering of the data
in the tree
if a binary tree contains an arithmetic expression then it traverse
infix notations,posfix notations,prefix notations
preorder traversal
input:two pointers ROOT1 and
ROOT2 OF THE TWO BINARY
TREES t1,t2
output:a binary treee containing all
the node t1,t2 ptr to the root as
ROOT
data structure:linked the data
strucure
steps:
if(ROOT1=NULL)THEN
ROOT=ROOT2
EXIT
Binary tree and operations

Binary tree and operations

  • 1.
  • 2.
  • 3.
    root node isdesigated wich has no parent if the imediate predecessor of the node is parent of the node then all imediate sucessor of a node are known as child child which is on left side is called left child and hat on right side is called right child Basic terminolgies
  • 5.
  • 6.
  • 7.
     the maximumno of nodes possible in a binary tree of height h is 2power of h-1 The minimum no of nodes possible in a binary tree Height h is h a binary tree has the minimum no of nodes one every parent has one child such kind of trees are called skew binary trees
  • 8.
  • 9.
    • The rootN of T is stored in TREE [1]. If a node occupies TREE [k] then its is stored in TREE and its is stored into TREE
  • 10.
    Advantage of sequentialrpresentation any node can acessed from any other node by calculating the index value data are stored without any pointers to their which are mentioned implicity programing lanuage where dynamic memmory allocation is not possible such as(BASIC ,FORTRAIN)ARRAY REPREPRESENTAION IS nly means to store a tree
  • 11.
    Disadvantage of sequentialreprentation other then the full of binary trees the majority of the array entries may be empty it allows only static representation it is in no way possible to enhance the tree structure if the array size will be limited insering new node to the tree or deleting a node in a tree data moved up and moved down in an array excessive amount of processing time
  • 12.
    linked list representation ofa binary tree they are two field s to stor the address of left child and right child of the node data is the current information of the node if one knows the address of the root node then form it other node can be acessed
  • 13.
    physical implementation ofa binary tree in memmory Algorithm build a tree input:ITEM is the data contet of the node i output: a binary tree with two sub-trees of the node i data structure: array representation of a binary tree
  • 14.
    operations of binarytrees  insertion: TO include a node into an existing binary tree deletion: TO delete a node from a non-empty binary tree Traversal: TO visit all the nodes in abinary tree in traversal they are three orders inorder -> LEFT->ROOT->RIGHT preorder -> ROOT->LEFT->RIGHT postorder-> LEFT->RIGHT->ROOT merge:TO merge two binary trees into a large one
  • 15.
    in this operationto insert a new node at any position in a binary tree we have a simple insertion for ex to insert a “g “ a new node two stops search the existence node second establish the link
  • 17.
    insert a binarytree using linked list • insert:KEY is the data content of the key node after new node is to be inserted an ITEM is the data content of the new node can be inserted • output: A node with data component ITEM inserted as an extrernal node after the node having data KEY if such a node does not exist with empty (s), that is, eiter child or both children IS/ARE ABSENT. • DATA STRUCTURE: linked structure of a binary tree. ROOT is the pointer to the root node.
  • 19.
    algorithm • PRINT “insertion is not possible as left child” • EXIT • EDIF • ELSE • IF(pf->RC =NULL) • new=GETNODE • new->DATA=ITEM • new->LC=new->RC=NULL • ptr->RC=new • else • print”insertion is not possibble as right child” • exit • end if • else • print”the key node is already has a child” • stop
  • 20.
    deletion • in deletionoperation can be carried out of two kinds of storage representation of binary trees • in ordernto delete a node in a binary tree it is required to reach at the parent node to be deleted • the link of the parent nodes whih stores the location of the node to be deleted is then set buy a NULL entry • input:given ITEM as data of the node with which the node can be identified for deletion • output:a binary tree without a node having a data ITEM • data stucture: array a storing binary trees SIZE denotes the size of a
  • 22.
    WHAT IS ATRAVERSAL? THE traversal operation is frequently used operation of a binary this operation to visit each node in the tree exactly once a full traversal of a binary tree gives a linear ordering of the data in the tree if a binary tree contains an arithmetic expression then it traverse infix notations,posfix notations,prefix notations
  • 23.
  • 27.
    input:two pointers ROOT1and ROOT2 OF THE TWO BINARY TREES t1,t2 output:a binary treee containing all the node t1,t2 ptr to the root as ROOT data structure:linked the data strucure steps: if(ROOT1=NULL)THEN ROOT=ROOT2 EXIT