Professional Documents
Culture Documents
return (p);
}
Ans: copy of T
49. If there are 16 leaf nodes in a complete (full) binary tree than the total number of nodes in the
tree are_____ 31__
50. A full binary tree with n non-leaf nodes contains__ n+1_____ leaf nodes.
51. What is the output of following code ? code is written for a binary tree.
int f(node *T)
{
int i;
if(T = = NULL)
return (0);
if(T->left = = NULL && T->right = = NULL)
return (0);
if (T->left = = NULL || T->right = = NULL)
return (f(T->left) + f( T->right));
return (1+ f((T->left) + f( T->right));
}
Ans: Counts number of nodes of degree 2
52. Depth of complete binary tree with n nodes is ____ O(logn)______.
53. The correct declaration of a node in a tree is__________
Ans: struct node
{
int data;
node *left;
node *right;
};
54. int f(node *T1,node *T2)
{
int i=0;
if(T1 = = NULL && T2 = = NULL)
i=1;
else if(T1->data = = T2->data)
{
i = f (T1->left , T2->left);
If(i)
i = f( T1->right), T2->right);
}
return i;
}
The above function is for___checking whether two trees are equal or not________.
55. Which of the expression indicates that the t represent an empty tree? Ans: (t = = NULL)
56. What are total number of leaf nodes in a complete binary tree with depth 3? Ans: 8 {Formula:
no. of leaf nodes = 2 d }
57. Consider the following code
int f(node *T, int cnt)
{
static int i=0;
if(T != NULL)
{
if(T->left = = NULL && T->right = = NULL)
{
cout<<T->data;
i++;
return i;
}
else
{
f (T->left ,i)
f( T->right,i);
}
}
}
It returns – Ans: Total number of leaf nodes
58. To represent hierarchical relationship between elements, which data structure is suitable : Tree
59. A binary tree whose every node has either zero or two children is called __extended binary
tree_____.
60. If a node having two children is deleted from a binary tree, it is replaced by its Inorder successor
61. The pre-order and post order traversal of a Binary Tree generates the same output. The tree can
have maximum One node
62. How many nodes in a tree have no ancestors? Ans: 1
63. A binary tree in which every non-leaf node has non-empty left and right subtrees is called a
strictly binary tree. Such a tree with 10 leaves has exactly 19 nodes { Formula : total no. of
nodes in a strictly binary tree =2N-1}
64. The number of possible binary trees with 3 nodes is 5. {refer formula from notes}
65. A tree can have 2 roots :FALSE
66. State true or false.
i) An empty tree is also a binary tree. : True
ii) In strictly binary tree, the outdegree of every node is either o or 2.: True
67. In which of the following tree, parent nodes has key greater than or equal to its both children?
Max heap
68. The children of a node in a tree are called as Siblings.
69. Each element present in a binary tree is called a__node____of that tree
70. The element that represents the base node of the tree is called the_root___of the tree
71. The no of nodes connected to a particular node of tree is called the _Degree___ of that tree
72. The maximum level of any leaf node in a tree is called the __Depth___ of the binary tree
73. when we traverse from root to leaf the operation is known as? Ans: Descending
Array Representation
74. if n is the number given to the node then left child occurs at position __2n+1_________
75. if n is the number given to the node then right child occurs at position ___2n+2________
76. which one of the following form of expression is obtained when the expression tree is traversed
in pre-order? Prefix
77. which one of the following form of expression is obtained when the expression tree is traversed
in post-order? Postfix
78. which of the following option is correct for the statement given below
i)The nodes to the original tree are called as internal nodes
ii) The new nodes that are added to the binary tree ,to make it an extended binary tree are
called external nodes.
Ans: both I and II are correct
79. which of the following option is correct for the statement given below
i)if the tree has n nodes then the no of branches it has is(n-1)
ii)except the root node every node in a tree has exactly two parents.
iii)any two nodes of a tree are connected by only one single path.
Ans:only I and III are correct
80. which of the following option is correct for the statement given below
i)for a binary tree of height h the maximum number of nodes can be 2 h+1-1.
ii)any binary tree with n internal node has (n-1) external nodes. {correct is n+1 external nodes}
Ans: only I is correct
81. which of the following is correct sequence of operation that should be performed to traverse a
non-empty binary tree in in-order traversal?
Ans: traverse the left sub-tree in in-order.
Visit the root.
Traverse the right sub-tree in in-order.
82. which of the following is the correct sequence of operation that should be performed to
traverse a non-empty binary tree in pre-order traversal?
Ans: visit the root .
traverse the left sub-tree in pre-order.
traverse the right sub tree in pre-order.
83. which of the following is the correct sequence of operation that should be performed to
traverse a non-empty binary tree in post-order traversal?
Ans: traverse the left sub-tree in post-order.
traverse the right sub tree in post-order.
Visit the root.
84. which of the following statement is correct?
i)if the value of balfact of any node is -1,then the height of the right sub tree of that node is one
more than the height of its left sub tree.
ii)if the value of balfact of any node is 0 then the height of its left and right sub-tree is exactly
the same.
iii)if the value of balfact of any node is 1 then the height of the left sub tree of that node is one
more than the height of its right sub tree.
108. A node that does not have any son is called Leaf node
109. The root node of a tree has level 0
110. which of the following is the correct structure that represents a node of a threaded
binary tree?
struct node
{
enum boolean left;
struct node *leftchild;
int data;
struct node *rightchild;
enum boolean right;
};
111. which of the following would be the correct structure that represents a node of the
general tree?
struct node
{
int data;
struct node *firstchild;
struct node*siblings;
};
112. Let T be a BST with 14 nodes & 60 as external path length. Then the internal path length
is--- 32 {Formula: E=I+2n}
113. Let T be a BST with 10 nodes & 30 as exeternal path length. Then the internal path
length is---10 {Formula: E=I+2n}
114. A BST is created by inserting following integers 50, 14, 65, 5, 20, 57, 91, 3, 8, 37, 60, 25
The number of nodes in Left & Right subtrees are 7,4
115. The numbers 1,2,3,4,5,6,7,8,9,10 will be inserted in BST, In resuting tree , the right
subtree of root contains 3 nodes. The root node will be 7
116. Construct BST for elements 5,3,7,2,4,8. The average number of comparisons required for
successful search in BST with these nodes is—2.33 {Formula: log 2(n)}
117. Construct BST for 10,8,15,12,13,7,9,17,20,18,4,5. What will be the parent node of node :
17 Ans:15
118. The preorder sequence of BST is 30,22,17,27,24,38,34,48. What is the postorder
sequence of the same tree Ans: 17,24,27,22,34,48,38,30
The preorder sequence of BST is 30,22,17,27,24,38,34,48. What is the Inorder sequence of the same tree
Ans: 17,22,24,27,30,34,38,48 { Formula: Sort the sequence to get inorder}