0% found this document useful (0 votes)
3 views8 pages

Binary Tree

The document discusses the construction of binary trees from various traversal sequences, emphasizing that Inorder combined with Preorder, Postorder, or Level-order can uniquely identify a tree. It also explains the definitions and differences between full and complete binary trees, as well as the concepts of depth and height. Additionally, it includes questions and answers related to binary tree properties and traversal methods.

Uploaded by

anildevaraj35
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
3 views8 pages

Binary Tree

The document discusses the construction of binary trees from various traversal sequences, emphasizing that Inorder combined with Preorder, Postorder, or Level-order can uniquely identify a tree. It also explains the definitions and differences between full and complete binary trees, as well as the concepts of depth and height. Additionally, it includes questions and answers related to binary tree properties and traversal methods.

Uploaded by

anildevaraj35
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

If you are given two binay tree traversal sequences, can you

construct the binary tree?


It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can
be constructed, otherwise not.

following combination can uniquely identify a tree.

Inorder and Preorder.


Inorder and Postorder.
Inorder and Level-order.

And following do not.

Postorder and Preorder.


Preorder and Level-order.
Postorder and Level-order.

Construct a Binary Tree from Postorder and Inorder


Given Postorder and Inorder traversals, construct the tree.
What is common in three different types of traversals (Inorder, Preorder and Postorder)?
a) Root is visited before right subtree
b) Left subtree is always visited before right subtree
c) Root is visited after left subtree
d) All of the above

The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively.
The postorder traversal of the binary tree is:
debfgca
A
edbgfca
B
edbfgca
C
defgbca
D

What does the following function do for a given binary tree?


int fun(struct node *root)
{
if (root == NULL)
return 0;
if (root->left == NULL && root->right == NULL)
return 0;
return 1 + fun(root->left) + fun(root->right);
}

Counts leaf nodes


A
Counts internal nodes
B
Returns height where height is defined as number of edges on the

C path from root to deepest node


Return diameter where diameter is number of edges on the longest

D path between any two nodes.

Which of the following pairs of traversals is not sufficient to build a binary tree from the given
traversals?
Preorder and Inorder
A
Preorder and Postorder
B
Inorder and Postorder
C
None of the Above
D

Which traversal of tree resembles the breadth first search of the graph?
Preorder
A
Inorder
B
Postorder
C
Level order
D
Which of the following tree traversal uses a queue data structure?
Preorder
A
Inorder
B
Postorder
C
Level order
D
Consider the following C program segment
struct CellNode
{
struct CelINode *leftchild;
int element;
struct CelINode *rightChild;
}

int Dosomething(struct CelINode *ptr)


{
int value = 0;
if (ptr != NULL)
{
if (ptr->leftChild != NULL)
value = 1 + DoSomething(ptr->leftChild);
if (ptr->rightChild != NULL)
value = max(value, 1 + DoSomething(ptr->rightChild));
}
return (value);
}
The value returned by the function DoSomething when a pointer to the root of a non-empty tree is
passed as argument is (GATE CS 2004)
The number of leaf nodes in the tree
A
The number of nodes in the tree
B
The number of internal nodes in the tree
C
The height of the tree
D
Depth Vs Height of a binary tree
 The depth of a node is the number of edges from the node to the tree's root node.
A root node will have a depth of 0.
 The height of a node is the number of edges on the longest path from the node to a
leaf.
A leaf node will have a height of 0.

What is a full binary tree?


a) Each node has exactly zero or two children
b) Each node has exactly two children
c) All the leaves are at the same level
d) Each node has exactly one or two children

What is a complete binary tree?


a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the bottom
level, which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the bottom
level, which is filled from left to right
d) A tree In which all nodes have degree 2

What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)

Answer: d

Explanation: The nodes are either a part of left sub tree or the right sub tree, so we don’t have to traverse all the

nodes, this means the complexity is lesser than n, in the average case, assuming the nodes are spread evenly, the

time complexity becomes O(logn).

Which of the following is not an advantage of trees?


a) Hierarchical structure
b) Faster search
c) Router algorithms
d) Undo/Redo operations in a notepad

In a full binary tree if number of internal nodes is I, then number of leaves L are?

a) L = 2*I
b) L = I + 1
c) L = I – 1
d) L = 2*I – 1

Answer: b
Explanation: Number of Leaf nodes in full binary tree is equal to 1 + Number of Internal Nodes i.e L = I + 1

In a full binary tree if number of internal nodes is I, then number of nodes N are?
a) N = 2*I
b) N = I + 1
c) N = I – 1
d) N = 2*I + 1
View Answer

Answer: d
Explanation: Relation between number of internal nodes(I) and nodes(N) is N = 2*I+1.

9. In a full binary tree if there are L leaves, then total number of nodes N are?
a) N = 2*L
b) N = L + 1
c) N = L – 1
d) N = 2*L – 1

Answer: d
Explanation: The relation between number of nodes(N) and leaves(L) is N=2*L-1.

You might also like