Find Inorder successor of a Node in BST

Find Inorder successor of a Node in BST.


Inorder traversal of a Binary Tree reads a Left most element first then a middle or root element and at last the right most element, so when we say successor of a Node, you have to return the next element of the Node in Inorder traversal.
 
Consider a below BST,

         50
       /    \
      /      \
     30       70
   /   \     /  \
  20   40   60  80
 /  \
10  25

Example:
Inorder Successor of Node 50 is 60
Inorder Successor of Node 25 is 30
Inorder Successor of Node 40 is 50
Inorder Successor of Node 80 is null
Inorder Successor of Node 70 is 80
  

Inorder traversal of a Binary Search Tree always return the data in sorted order. So one way to find is to do a Inorder traversal which would be 

10 20 25 30 40 50 60 70 80

and then you can sequentially search for the next element of the given node which is Inorder successor of a Node. this approach would have O(n) time and space complexity. lets optimize it to O(h) where h is height of tree. (Note: in case of skewed tree it will still be O(n)) 

Inorder Successor In BST

There are 2 case in finding Inorder successor of a Node in BST.

  • Given Node has Right Subtree
  • Given Node doesn't has right subtree

Given Node has Right Subtree, 


In this case, Node 50 has right subtree so the next element would obviously be the left most element in the right sub tree as that how Inorder traversal goes.

Given Node doesn't has right subtree,

In this case (Node 22), where there is no right sub tree, so the next element that is read in inorder successor is the root node 25 and the root node will always encountered when you visit left of any node (this is what is in-order traversal you first visit left most node, so if there is a node and it has left node, you will first visit that and then the root node.)

In above tree, we visited left side 3 times, one from Node 50, one from Node 30 and one from Node 25, so the last left taken is the answer which in this case is 25.

Consider Node 40, the last left you will take is only from Node 50, so Inorder successor of 40 is Node 50.

Inorder successor of Binary Search Tree in Java.

package javabypatel.bst;

public class InOrderSuccessor {
    public static void main(String[] args) {
        new InOrderSuccessor();
    }

    public InOrderSuccessor() {
        Node rootNode = null;
        rootNode = addNode(rootNode, 50);
        rootNode = addNode(rootNode, 30);
        rootNode = addNode(rootNode, 70);
        rootNode = addNode(rootNode, 20);
        rootNode = addNode(rootNode, 40);
        rootNode = addNode(rootNode, 10);
        rootNode = addNode(rootNode, 25);
        rootNode = addNode(rootNode, 60);
        rootNode = addNode(rootNode, 80);

        System.out.println(inorderSuccessor(rootNode, 70, null).getData());
    }

    private Node inorderSuccessor(Node root, int k, Node lastLeftNodeVisited) {
        if (root == null) {
            return root;
        }

        if (root.getData() == k) {
            if (root.getRight() != null) {
                return findSmallestInLeft(root.getRight());
            } else {
                return lastLeftNodeVisited;
            }
        }

        if (k < root.getData()) {
            return inorderSuccessor(root.getLeft(), k, root);
        } else {
            return inorderSuccessor(root.getRight(), k, lastLeftNodeVisited);
        }
    }

    private Node findSmallestInLeft(Node root) {
        if (root == null || root.getLeft() == null) {
            return root;
        }

        return findSmallestInLeft(root.getLeft());
    }

    private Node addNode(Node rootNode, int i) {
        if (rootNode == null) {
            return new Node(i);
        } else {
            if (i > rootNode.getData()) {
                Node nodeToAdd = addNode(rootNode.getRight(), i);
                rootNode.setRight(nodeToAdd);

            } else {
                Node nodeToAdd = addNode(rootNode.getLeft(), i);
                rootNode.setLeft(nodeToAdd);
            }
        }
        return rootNode;
    }
}
 
package javabypatel.bst;

public class Node {
    private int data;
    private Node left;
    private Node right;

    public Node(int data) {
        this.data = data;
    }

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public Node getLeft() {
        return left;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public Node getRight() {
        return right;
    }

    public void setRight(Node right) {
        this.right = right;
    }
}


Find largest number in Binary Search Tree which is less than or equal to N

Largest number in Binary Search Tree which is less than or equal to N.


We have a binary search tree and a number N. Our goal is to find the greatest number in the binary search tree that is less than or equal to N. Print -1 if the the value of the element doesn't exists.

We have to find the largest number inside the binary search tree that is smaller than or equal to the target number N.

Lets see sample input and output:

Top Binary Tree Interview Questions.

Binary Tree Interview Questions.


Binary tree questions is very common during interviews. In this post we will focus on Top Binary tree and Binary Search tree interview questions and answers. 


In this post we will look at,
1. Basic Interview Questions on Binary Tree.
2. Most commonly asked Interview Questions on Binary Tree.

Basic Interview Questions on Binary Tree.

Question 1: What are the types of Binary tree?
Answer
Types of Binary Tree in Data Structure. Let's see Binary Tree types with example. There are mainly 3 types of Binary trees.

  1. Full binary tree / Proper binary tree / 2-tree / Strictly binary tree) 
  2. Perfect Binary Tree. 
  3. Complete Binary Tree:
Full binary tree / Proper binary tree / 2-tree / Strictly binary tree)
Full Binary Tree is a tree in which every node except leaves/leaf node has either 0 or 2 children.
There will be no leaves with only 1 child.
 

Example of Full Binary Tree:  More ...


Question 2:
Explain Binary tree Traversals with example?
Answer:
There are 2 types of Graph traversal algorithms Breadth first traversal and Depth First traversal. 
Tree is a special kind of Graph in which Breadth first traversal and Depth First traversal is divided as follows,
  1. Breadth First Traversal.
    • Level Order Traversal 
  2. Depth First Traversal
    • Preorder traversal
    • Inorder traversal
    • Postorder traversal
Breadth First Traversal
Breadth First Traversal is a traversing way where child at same levels are read first before visiting their child. which is nothing but a LEVEL-ORDER Traversal. More....



Question 3:
How to add a Node in Binary Tree?
Answer:
To add a Node in a Binary Tree, Start scanning a Binary Tree level by level and wherever we encounter vacant position, place a new Node there.

See below image to get better understanding of position of a new Node to insert.
Given a binary tree, we need to add a Node with value 8 marked in dotted lines below in its correct position. 

Java Program to Insert Node in Bina More....


Question 4:
How to add a Node in Binary Search Tree?
Answer:
While adding a Node in a Binary Search Tree, it should follow below rules,
  1. All values descending on the Left side of a node should be less than (or equal to) the node itself.
  2. All values descending on the Right side of a node should be greater than (or equal to) the node itself.

Java Program to Insert Node in Bina More....

Question 5:
How to Delete a node in Binary Search Tree?
Answer:
There are 3 cases that need to be considered while deleting a node from Binary Search Tree.
  1. Node to delete has no children that is no left child and no right child present. Case 1 in below image.
  2. Node to delete has only one child either left child or right child present. Case 2 in below image. 
  3. Node to delete has both child that is left child and right child present. Case 3 in below image.
 Case 1:
    For case 1, it is very much straightforward,

    1.
Search for the node that need to be deleted. More....



Frequently Asked Interview Questions on Binary Tree.

Question 6:
Check if Two Binary Trees are identical?
Answer:
Two Binary Trees are considered equal if they are structurally identical and the nodes have the same value.

See below image for better understanding of which Trees are called Identical and which not.

More...


Question 7:
Check a given two Binary Trees are Mirror Image of each other?
Answer:
Two Binary Trees are considered mirror image of each other if there left and right child of every node is inter-exchange. (Left child moved to Right and Right chile moved to Left)

See below image for better understanding of which Trees are called Mirror Image of each other

Question 8:
Connect nodes at same level in a Binary Tree?
Answer:
Let us first understand what we want to achieve? what is the input and what will be the expected output.

 Binary Tree is given to you,

  1. some node of  tree has both left and right child present,
  2. some node of tree has only left child present and 
  3. some node of tree has only right child present, 
  4. nextRight pointer of all the node initially is null.
Our task is to connect nextRight pointer of each node to its adjacent node.   

1. If the immediate adjacent node is not present then connect to next adjacent node and
2. If next adjacent node is not present then connect to next to next adjacent node and
3. If next to next adjacent node is not present then search until you find the adjacent node along
    the same Level and connect to it.
4. If the adjacent node is not present at same level then connect it to null. 


Question 9:
Connect nodes at same level in a Binary Tree using constant extra space?
Answer:
This problem is variation of above question number 8. you can see details of this post on this link.
Connect nodes at same level in a binary tree using constant extra space.


Question 10:
Construct a Binary Tree from In-order and Level-order traversals?
Answer:
Two traversals are given as input,
   
int[] inOrder =    { 4, 2, 6, 5, 7, 1, 3 };
int[] levelOrder = { 1, 2, 3, 4, 5, 6, 7 };

By using above two given In order and Level Order traversal, construct Binary Tree like shown below More...



Question 11:
Construct a Binary Tree from In-order and Pre-order traversals?
Answer:
Two traversals are given as input,
   
int inorder[] =  {20, 30, 35, 40, 45, 50, 55, 60, 70};
int preorder[] = {50, 40, 30, 20, 35, 45, 60, 55, 70};
 

By using above 2 given In order and Pre Order traversal, construct Binary Tree like shown below,
More...


Question 12:
Zig Zag or Spiral Traversal of Binary Tree?
Answer:
Given a binary tree, write a program to print nodes of the tree in spiral order. 
You can also say it as Spiral order traversal of a tree. Let us first understand what we want to achieve? what is the input and what will be the expected output?

If you observe Zig Zag Traversing is very similar to Level order traversal with few modification.
More... 


Question 13:
Boundary Traversal of Binary Tree?
Answer:
We have to print the boundary nodes of given Binary Tree in anti-clockwise starting from the root.
  1. Print Left boundary Nodes. 
  2. Print Leaf Nodes. 
  3. Print Right boundary Nodes in Bottom up fashion.
Let's take an example and try to understand. For reference we will More...


Question 14:
Print a Binary Tree in Vertical Order?
Answer:
Given a binary tree, print it vertically.

Vertical order Traversal of a tree is little bit different than Pre order, Post order, In order and Level order traversal.

We need to identify, which node will be part of Line 1, Line 2, Line 3 and so on, How to do that? If you observe, then there is a close relation between each line from root. More...



Question 15:
Print Nodes in Top View of Binary Tree?
Answer:
Given a binary tree, print the nodes that is visible, when the tree is viewed from the top.

Let us first understand what we want to achieve? what is the input and what will be the expected output?


Top view means, when we look the tree from the top, the nodes that are visible will be called the top view of the tree. So in the above image,

Solution: "If two nodes have the same Horizontal Distance from root, then they are on same vertical line." Lets understand this line in more detail. More...



Question 16:
Print Nodes in Bottom View of Binary Tree?
Answer:
Given a binary tree, print the nodes that is visible, when the tree is viewed from the bottom.

Let us first understand what we want to achieve? what is the input and what will be the expected output?


Bottom view means, when we look the tree from the bottom, the nodes that are visible will be called the bottom view of the tree. So in the above image,

Solution for printing the nodes visible from bottom view of binary tree is very similar to vertical traversal of binary tree. More...



Question 17:
Find Kth smallest element in BST(Binary Search Tree)?
Answer:
Solution is very simple:
  1. Take a variable counter, which keep track of number of smallest element read till now. 
  2. Do In order traversal, instead of printing the node in in-order traversal, increment the counter till it matches K. 
  3. Check whether counter value is equal to K. 
  4. If YES, then current node is Kth smallest node and return it. If NO, then return -1 as indication that given 'K' is invalid. More...


Question 18:
Find Kth largest element in BST(Binary Search Tree)?
Answer:
Solution is very simple:
  1. Take a variable counter, which keep track of number of largest element read till now.
  2. Do In-order traversal starting from right side (Right to Left instead of Left to Right), instead of printing the node in in-order traversal, increment the counter till it matches K.
  3. Check whether counter value is equal to K.
  4. If YES, then current node is Kth largest node and return it. If NO, then return -1 as indication that given 'K' is invalid.. More...


Question 19:
Find diameter of Binary Tree.?
Answer:
A longest path or route between any two nodes in a tree is called as Diameter/Width of binary tree.

The diameter of tree may or may not pass through the root.
The diagram below shows two trees each with diameter 7, diameter are shaded with blue nodes.
We will discuss 3 solutions,

  1. By using Global variable.
  2. By computing height and diameter of each node.
  3. By computing height and diameter of each node in optimized way. More...


Question 20:
Given an array of numbers, verify whether it is the correct Preorder traversal sequence of a binary search tree?
Answer:
You are given an array of numbers which represents Preorder traversal of Binary Search Tree.
Verify whether it is a correct Preorder sequence or not.

Lets understand what is the input and the expected output.

Input: [40, 30, 35, 20, 80, 100]
Output: Invalid Preorder traversal

Input: [45, 25, 15, 35, 75]
Output: Valid Preorder traversal

Input: [50, 39, 44, 28, 85]
Output: Invalid Preorder traversal. More..



Question 21:
Construct a Binary Tree from In-order and Post-order traversals
Answer:
Let us first understand what we want to achieve? what is the input and what will be the expected output?

Question: Two traversals are given as input,
  
int inOrder[] =   {20, 30, 35, 40, 45, 50, 55, 60, 70};
int postOrder[] = {20, 35, 30, 45, 40, 55, 70, 60, 50};
By using above 2 given In order and Post Order traversal, construct Binary Tree More..
  

Question 22:
Serialize and Deserialize a Binary Tree.
Answer:
Design an algorithm to serialize and deserialize given Binary Tree. Serialization is to store tree in a File/String, so that it can be later restored. Deserialization is reading tree back from file.Serialization:
For Serialization process, we can read the given Binary Tree in any order and create a String representation of tree as long as same String is capable of converting back to same given Binary Tree.
    

Question 23:
Convert Sorted Array to Balanced Binary Search Tree(BST).
Answer:
Given a sorted array, create a Balanced Binary Search Tree using array elements.
A Binary Search Tree is called Balanced if, the height of left subtree and height of right subtree of Root differ by atmost 1.

We are given a sorted array, So which element we will pick as a Root Node for our BST such that it will be balanced.
If we pick the middle element of the array as Root node and distribute the left portion More..

    

Question 24:
Convert Sorted Linked List to balanced BST.
Answer:
Given a singly Linked List where elements are sorted in ascending orderconvert it to a height balanced BST.

A Binary Search Tree is called balanced if the height of left subtree and height of right subtree of Root differ by at most 1.

Lets understand the problem statement graphically and it will be more clear, More..



Question 25:
Print Nodes at K distance from Root in Binary Tree.
Answer:
Given a Binary Tree, Print all Nodes that are at K distance from root node in Binary Tree.
We can also think of this question as Print all nodes that belong to Level K.

Lets understand what will be input and expected output with the help of an example. More..



Question 26:
Print nodes at K distance from Leaf node in Binary tree.
Answer:
Given a Binary Tree, Print all Nodes that are at K distance from leaf node in Binary Tree.
Lets understand what will be input and expected output with the help of an example.

If k = 1. It means we need to print all nodes that are at distance 1 from Leaf node.

In Case 2, we have 4 leaf nodes (Node 1, Node 10, Node 5, Node7).
Node at distance K that is Node at distance 1 from leaf Node 1 is Node 2 (Print 2)
Node at distance K that is Node at distance 1 from leaf Node 10 is Node 9 (Print 9)
Node at distance K that is Node at distance 1 from leaf Node 5 is Node 6 (Print 6)
Node at distance K that is Node at distance 1 from leaf Node 7 is Node 6 (6 already printed, ignore)



Question 27:
Get Level/Height of node in binary tree.
Answer:
Given a binary tree, you need to find the height of a given node in the tree. Finding level of node of binary tree is equivalent to finding Height of node of binary tree.

There are 2 approach to find level of node in binary tree,

  1. Recursive approach. 
  2. Iterative approach. More..
 


Question 28:
Check if two nodes are cousins in a Binary Tree.
Answer:
Given the binary Tree and the two nodes say ‘p’ and ‘q’, determine whether the two nodes are cousins of each other or not.

Two nodes are cousins if,
  1. They are not siblings (Children of same parent).  
  2. They are on the same level.
Two nodes are cousins of each other if they are at same level and have different parents. More..

 


Question 29:
Check whether Binary Tree is foldable or not.
Answer:
Check whether given binary tree can be folded or not. Binary Tree is said to be Foldable if nodes of Left and Right Subtree are exact mirror of each other.

  1. Traverse Binary Tree and compare left node of Left subtree with right node of Right subtree. 
  2. Traverse Binary Tree and compare right node of Left subtree with left node of Right subtree. 
  3. In both steps 1 and 2 above, check both left and right node is null or both left and right node is not null, if Yes, then Tree is foldable and has identitical structure otherwise not. More..

 You may also like to see


Top 10 Matrix Interview Questions in Java

What is Hashmap data structure? What is the need of Hashmap? 

What is Hashcode? Can 2 objects have same hashcode?

How time complexity of Hashmap get() and put() operation is O(1)? Is it O(1) in any condition?

What is Load factor and Rehashing in Hashmap?

Advanced Multithreading Interview Questions In Java 

How ConcurrentHashMap works and ConcurrentHashMap interview questions

Enjoy !!!! 

If you find any issue in post or face any error while implementing, Please comment.

Types of Binary Tree.

Types of Binary Tree.


Types of Binary Tree in Data Structure. Let's see Binary Tree types with example. There are mainly 3 types of Binary trees.
  1. Full binary tree / Proper binary tree / 2-tree / Strictly binary tree) 
  2. Perfect Binary Tree. 
  3. Complete Binary Tree:

Binary Tree Inorder Traversal in Java

Binary Tree Inorder Traversal in Java OR
Inorder Traversal Java Program


Inorder traversal is one of the way to traverse binary Tree. In Inorder traversal, Left subtree is read first then Root Node and then Right subtree.

Binary Tree Inorder traversal is a very popular interview question so better to understand it properly. 

There are 2 ways of doing Inorder traversal,
  1. Recursive Inorder traversal of Binary tree.
  2. Iterative Inorder traversal of Binary tree.

Inorder Traversal Binary Tree Java Program

Binary Tree Inorder Traversal in Java


In Inorder traversal, Left subtree is read first then Root Node and then Right subtree.

Inorder traversal of Binary Tree is very popular interview question.
 
There are 2 ways to do Inorder traversal,
1. Recursive Inorder traversal of Binary tree.
2. Iterative Inorder traversal of Binary tree.
   
Inorder traversal example.


Postorder Traversal Java Program

Binary Tree Postorder Traversal in Java


Postorder traversal is one of the way to traverse binary Tree. In postorder traversal Left subtree is read first then Right subtree and then Root Node.

Binary Tree Postorder traversal algorithm is a very popular interview question so better to understand it properly.

There are 2 ways of doing Postorder traversal,
  1. Recursive Postorder traversal of Binary tree.
  2. Iterative Postorder traversal of Binary tree.

Binary Tree Preorder Traversal in Java

Binary Tree Preorder Traversal in Java


Preorder traversal is one of the way to traverse the binary Tree. In Preorder traversal Root node is read first then Left child and at last Right child.

Binary Tree Preorder traversal is a very popular interview question so better to understand it properly.

There are 2 ways to doing Preorder traversal,
  1. Recursive Preorder traversal of Binary tree.
  2. Iterative Preorder traversal of Binary tree.

Print nodes at K distance from Leaf node in Binary tree.

Print nodes at K distance from Leaf in binary tree. OR
Print all nodes that are at distance k from a leaf node.


Given a Binary Tree, Print all Nodes that are at K distance from leaf node in Binary Tree. Lets understand what will be input and expected output with the help of an example.


If k = 1. It means we need to print all nodes that are at distance 1 from Leaf node.

In Case 2, we have 4 leaf nodes (Node 1, Node 10, Node 5, Node7).
Node at distance K that is Node at distance 1 from leaf Node 1 is Node 2 (Print 2)
Node at distance K that is Node at distance 1 from leaf Node 10 is Node 9 (Print 9)
Node at distance K that is Node at distance 1 from leaf Node 5 is Node 6 (Print 6)
Node at distance K that is Node at distance 1 from leaf Node 7 is Node 6 (6 already printed, ignore)

Print Nodes at K distance from Root in Binary Tree

Print nodes at K distance from root in binary tree. OR
Print nodes at Level K.


Given a Binary Tree, Print all Nodes that are at K distance from root node in Binary Tree. We can also think of this question as Print all nodes that belong to Level K.
 
Lets understand what will be input and expected output with the help of an example.
 

If k = 2. It means we need to print all nodes that are at distance 2 from Root node.
It also means we need to print all nodes at Level 2, because all Nodes of Level 2 will be at same distance from Root Node.

Convert Sorted Linked List to balanced BST

Convert Sorted Linked list to balanced Binary Search Tree

Convert sorted list to binary search tree

Lets simplify the question statement, Given a singly Linked List where elements are sorted in  ascending order convert it to a height balanced BST.

A Binary Search Tree is called balanced if the height of left subtree and height of right subtree of Root differ by at most 1.

Lets understand the problem statement graphically and it will be more clear,

Sorted Array to Balanced Binary Search Tree (BST)

Convert Sorted Array to Balanced Binary Search Tree

Given a sorted array, create a Balanced Binary Search Tree using array elements. A Binary Search Tree is called Balanced if, the height of left subtree and height of right subtree of Root differ by at most 1.

Lets understand the problem statement graphically and it will be more clear,

Construct a Binary Tree from In-order and Post-order traversals.

How to construct a Binary Tree from given In order and Post order traversals.


Let us first understand what we want to achieve? what is the input and what will be the expected output?

Question:
Two traversals are given as input,
  int inOrder[] =   {20, 30, 35, 40, 45, 50, 55, 60, 70};
  int postOrder[] = {20, 35, 30, 45, 40, 55, 70, 60, 50};
By using above 2 given In order and Post Order traversal, construct Binary Tree like shown below,

Verify Preorder Sequence Of Binary Search Tree(BST)

Check if a given array can represent Preorder Traversal of Binary Search Tree. OR
Check if given Preorder traversal is valid BST (Binary Search Tree). OR
Given an array of numbers, verify whether it is the correct Preorder traversal sequence of a binary search tree.


You are given an array of numbers which represents Preorder traversal of Binary Search Tree.
Verify whether it is a correct Preorder sequence or not.


Lets understand what is the input and the expected output.

Input: [40, 30, 35, 20, 80, 100] Output: Invalid Preorder traversal
 

Input: [45, 25, 15, 35, 75]
Output: Valid Preorder traversal

Input: [50, 39, 44, 28, 85]
Output: Invalid Preorder traversal
 

Input: [10, 25, 5]
Output: Invalid Preorder traversal
 


Input: [30, 20, 10, 40, 50]
Output: Valid Preorder traversal

Diameter of Binary Tree.

Find diameter of Binary Tree.


What is Diameter of a Binary Tree?

A longest path or route between any two nodes in a tree is called as Diameter/Width of binary tree.
The diameter of tree may or may not pass through the root.
The diagram below shows two trees each with diameter 7, diameter are shaded with blue nodes.

Diameter of node = height of Left sub tree of node + height of Right sub tree of node + 1 (node itself).

Find Kth largest element in BST(Binary Search Tree)

Find Kth largest element in Binary Search Tree.


Lets understand the problem statement correctly, What is the Input and the expected output.


Find Kth smallest element in BST(Binary Search Tree)

Find Kth smallest element in Binary Search Tree.


Lets understand the problem statement correctly, What is the Input and the expected output.


Print Nodes in Bottom View of Binary Tree.


Print the bottom view of Binary Tree



Given a binary tree, print the nodes that is visible, when the tree is viewed from the bottom.


Let us first understand what we want to achieve? what is the input and what will be the expected output?


Bottom view means, when we look the tree from the bottom, the nodes that are visible will be called the bottom view of the tree. So in the above image,

Print Nodes in Top View of Binary Tree


Print the top view of Binary Tree



Given a binary tree, print the nodes that is visible, when the tree is viewed from the top.

Let us first understand what we want to achieve? what is the input and what will be the expected output?

Top view means, when we look the tree from the top, the nodes that are visible will be called the top view of the tree. So in the above image,

Print a Binary Tree in Vertical Order. Find Vertical Sum of given Binary Tree.

Print Binary Tree in Vertical Order OR
Print the Binary Tree in Vertical Order Path OR
Vertical order traversal of a Binary Tree.
Find Vertical Sum of given Binary Tree


Given a binary tree, print it vertically.

Let us first understand what we want to achieve? what is the input and what will be the expected output?

Note:
Vertical order traversal of Tree shown above will be 
Print data present at Line 1 ( 4 )
Print data present at Line 2 ( 2 )
Print data present at Line 3 ( 1, 5, 6 )
Print data present at Line 4 ( 3 )
Print data present at Line 5 ( 7 )