Professional Documents
Culture Documents
Data Structures - 20E029 - Assignment2
Data Structures - 20E029 - Assignment2
Data Structures - 20E029 - Assignment2
NAME: JAYA
DHARSHINI H
REG NO:20E029
Problem 1:
Develop a program using any programming language to calculate the balance factor for a
given node in an AVL tree.
Note: Balance factor for a node can be calculated based on the difference between the
height of the left subtree and the height of the right subtree.
Problem 5:
a. Develop a program using any programming language to print those nodes in a binary
tree that does not have a sibling.
public static void NodeWithoutSibilings(Treenode root){
if(root==null)
return;
if(root.right!=null&&root.left!=null){
NodeWithoutSibilings(root.left);
NodeWithoutSibilings(root.right);
}
else if(root.left!=null){
System.out.print(root.left.data+" ");
NodeWithoutSibilings(root.left);
}
else if(root.right!=null){
System.out.print(root.right.data+" ");
NodeWithoutSibilings(root.right);
}
}
b. Develop a program using any programming language to count the number of leaf nodes
in a binary tree of size N.
public static int LeafNodecount(Treenode root){
if(root==null)
return 0;
if(root.left==null && root.right==null)
return 1;
return LeafNodecount(root.left)+LeafNodecount(root.right);
}