Key Fin 2021 2
Key Fin 2021 2
int f(int n)
{
int s = 0;
while(n > 1)
{
n = n/2;
s++;
}
return s;
}
Ans:
A. 4 b * d 9 + a 12 - * /
B. / 12 a – b 9 + d 4 *
C. 12 – a * b + 9 / d * 4
D. 12 a – b 9 + * d 4 * /
Ans:
D
3- Consider the binary tree.
2 6
e
2
F 9
4
3 7
4
4I
8
5
8
8
8
What is the pre-order traverse? 8
8
A. 1 2 3 4 5 6 7 8 9 8
Q
B. 1 2 4 9 6 3 8 5 7
C. 4 9 2 8 5 3 7 6 1
D. 4 2 9 1 8 3 5 6 7
E. 1 2 6 4 9 3 7 8 5
Ans:
Ans:
Ans:
void main()
{
int *q;
int v[8]={3,2,7,-2,5,6,7,9};
q = fun(v);
printf("%d ", ____Missing_1___);
printf("%d ", ____Missing_2___);
}
However, part of the code is missing (indicated by __________). The code is supposed to
give the output
7 -2
7- What are the time complexities of finding 9th element from beginning and 9th element
from end in a singly linked list? Let n be the number of nodes in linked list, and assume
that n>9.
A.) O(n) and O(n) B.) O(1) and O(1) C.) O(n) and O(1) D.) O(1) and O(n)
Ans:
list->next->next->next->data
Ans:
9- Consider linked list is used to implement the Stack then which of the following node is
considered as Top of the Stack ?
A.) Any Node B.) Last Node C.) First Node D.) Middle Node
Ans:
10- When a new element is added in the middle of singly linked list then
A.) Only elements that appear after the new element need to be moved
B.) Only elements that appear before the new element need to be moved
C.) No need to move element
D.) Only elements that appear after the new element and before need to be moved
Ans:
11- What is the output of following function if the start pointing to first node of the linked
list:
1->2->3->4->5->6
Ans:
12- Which binary tree does yield postorder and inorder traverses as
Inorder: N, M, P, O, Q
Postorder: N, P, Q, O, M
A.) B.)
C) D.)
Ans:
13- Which of the following properties are obeyed by all three tree traversals?
a) Left subtrees are visited before right subtrees
b) Right subtrees are visited before left subtrees
c) Root node is visited before left subtree
d) Root node is visited before right subtree
Ans:
14- Suppose that T is a binary tree with 14 nodes. What is the minimum possible depth of T?
a.) 0 b.) 3 c.) 4 d.) 5
Ans:
B
15- Suppose that we constructed a binary search tree for sorting the list of items 14 1 2 5 16
4 in ascending order. Then we remove the root by replacing it with something from the
left subtree. What will be the new root?
Ans:
D
16- Which of the following is not a binary search tree?
A.)
3 7
e
2
F
2
4 6
4I
B.)
4 7
e
2
F
3 6
4
4
4I
4I
C.)
6 3
e 2
2
F
7 2
4
4I
D.)
14
44
44
2 44 16
e 14
2
F 5
1
4
4I
4
4
4I
Ans:
17- Suppose that we constructed a binary search tree for sorting the list of items 23 11 27 7
25 17 6 14 9 in ascending order. Then we remove the root from the tree. Which of
the following (parent, child) pair cannot exist in the tree?
Ans:
B
19. Which of the following is the prefix notation of the expression
AB+CD-*?
(a) (A+B)*(C-D)
(b) *+AB-CD
(c) +*AB-CD
(d) -CD*+AB
Ans:
B
20. Choose correct output for the following sequence of stack operations.
push(5)
push(8)
pop
push(2)
push(5)
pop
pop
pop
push(1)
pop
Ans:
21- The post- order traversal of a binary tree is DEBFCA. Find out the pre-order traverse.
C
22-The in-order traversal of a binary tree is ABFCD. Find out the pre-order traverse.
23- The best performance occurs for quick sort when the partition splits the
array of size n into
a) n/2 : (n/2) – 1
b) n/2 : n/3
c) n/4 : 3n/2
d) n/4 : 3n/4
Ans:
24- A machine needs a minimum of 20 sec to sort m elements by Quick sort. The
minimum time needed to sort 2m elements will be approximately:
a) 2m+40 sec
b) 2m sec
c) 40 sec
d) m+20 sec
Ans:
25- Which of the following code segments deletes the element pointed to by q from a doubly
linked list? Assume that q does not point to the first or the last element.
a.) q -> left -> right = q -> right; q -> right-> left = q-> left;
b.) q -> left -> right = q -> left; q -> right-> left = q-> right;
c.) q -> left -> left = q -> right; q -> right-> right = q-> left;
d.) q -> left -> left = q -> left; q -> right-> right = q-> right;
Ans:
A
26- Which of the following code segments deletes the first element (pointed to by list) from a
linear doubly linked list?
a.) list -> left = list -> right; list -> right = list -> left;
b.) list = list -> right; list -> left = null;
c.) list = list -> right; list -> right = null;
d.) list -> left-> left = list -> left; list -> right-> right = list -> right;
Ans:
a) v[1][1] is ‘M’
b) *v[1] is ‘U’
c) v[-1][0] is ‘C’
d) v[1]-q[1] is 2
Ans:
char *str[3];
fun(&str[1]);
if XYZ is printed:
Ans:
char *str[3];
fun(&str[1]);
if 78 is printed:
Ans: