0% found this document useful (0 votes)
3 views

Selfstudys Com File (21)

The document contains a programming and data structures test with 25 questions covering various topics such as data structures, tree traversals, and algorithms. Each question provides multiple-choice answers, and the document includes answer keys and hints for some questions. The test assesses knowledge on concepts like AVL trees, heaps, binary trees, and graph traversal techniques.

Uploaded by

vyshnavikundur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Selfstudys Com File (21)

The document contains a programming and data structures test with 25 questions covering various topics such as data structures, tree traversals, and algorithms. Each question provides multiple-choice answers, and the document includes answer keys and hints for some questions. The test assesses knowledge on concepts like AVL trees, heaps, binary trees, and graph traversal techniques.

Uploaded by

vyshnavikundur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming and Data Structures Test 4

Number of Questions: 25 Section Marks: 30

Directions for questions 1 to 25: Select the correct alterna- 5. Which of the following is TRUE about the AVL tree?
tive from the given choices. (1) AVL tree is a binary tree.
1. Which of the following data structure(s) can be used to (2) The search time of AVL tree will be always less
represent Stack, Queue, Binary Tree, Hash Table, Heap than (or) equal to the search time of binary search
and Graph? tree.
(A) Array (B) Singly linked list (3) AVL tree is binary search tree with maximum bal-
(C) Doubly linked list (D) Both (A) and (C) ancing factor of 2.
(A) Only (1) (B) Only (1) and (2)
2. Which of the following is a min heap?
(C) Only (1) and (3) (D) All the above
12 6. Which of the following is suitable for the data that con-
tains a relationship between pairs of elements, which is
not necessarily hierarchical in nature?
(A) 14 16 (A) Heaps (B) AVL Trees
(C) Graphs (D) B-Trees
18 13 17 18 7. What is the Number of Null links in a Binary Tree of
‘n’ nodes?
6 (A) n (B) n + 1
(C) n – 1 (D) n/2
8. What is the number of stacks that should be used to
(B) 7 8
implement a queue?
(A) 1 (B) 2
9
(C) 3 (D) 4
10
9. Consider the recursive function for fibonacci sequence:
32 fib (n)
{
if (n ==0)
(C) 64 128 return 0;
else if (n==1)
256 return 1;
512 2048 else
return fib (n – 1) + fib (n – 2);
2 }
What is the Number of additions required, when fib(n)
is invoked ?
4 8
(A) fib(n + 1) – 1 (B) fib (n + 1) + 1
(D) (C) fib (n + 1) – n (D) fib (n + 1) + n
16 128
32 64 10. Which of the following tree traversals are necessary to
get the unique pattern of a tree structure?
256 (A) Only In-order
3. Which traversal of a binary search tree will give the (B) In-order and pre-order
result in an ascending order of elements. (C) Post-order and pre-order
(A) Preorder (D) All the above
(B) In-order Common data for questions 11 and 12:
(C) Post-order Consider the following routines:
(D) None of the above (a special code is required to struct Binary
print elements in ascending order) {
4. Which of the following cannot be implemented using struct Binary * Left ;
self-referential structure? int data;
(A) Graphs (B) AVL trees struct Binary * Right;
(C) Splay trees (D) B-Trees }
3.74 | Programming and Data Structures Test 4

void F1 (struct Binary *t) (A) queue remains same


{ (B) elements will get reversed in a queue
if (t) (C) elements are removed and reinserted in the same
{ queue
printf(“%d”, t → data); (D) queue remains empty
F2(t → Left); 15. Fill in the blanks for the routine A( ).
F2(t → Right); A( ) will delete the elements in cir-
} cular queue.
} Initially Front = Rear = –1
void F2(struct binary * t) A(Q, N, Front, Rear, Y) // N is size
{ of a queue, Q is an array to store
circular Queue.
if (t)
{
{
if (Front == –1)
F1(t → Left); {
printf(“%d”, t → data); printf(“Queue is underflow”);
F1 (t → Right); exit (1);
} }
} Y = Q(Front);
Let us consider a tree if(I)
Front = Rear = –1;
A
else
{
B D if (Front == N)
(II);
C else
E
Front = Front + 1;
}
F return Y;
(A) I. Front == Rear +1 II. Front = –1
11. If F1(t) is called on the above tree with t as root node (B) I. Front == Rear II. Front = –1
(A), what is its output? (C) I. Front == (Rear +1) II. Front = 0
(A) ABCDEF (B) ACBFED (D) I. Front == Rear II. Front = 0
(C) ABDCFE (D) ACBEFD 16. Consider the following routine:
12. When F2(t) is called on this tree, with root as the struct node
parameter that is (F2(root)), what is its output? {
(A) BCADEF (B) BCDEFA int data;
(C) DEFBCA (D) DEFABC struct node → link;
13. What is the prefix expression of the expression a + b ∗ };
c/d ∧ e ∧ f – g void DO (struct node → p, struct node
(A) –/ ∗ + a b c d ∧ ∧ e f g → q)
(B) – + a/∗ b c ∧ d ∧ e f g {
(C) – + a ∧ ∧ / ∗ b c d e f g if (q)
(D) ∧ ∧ + a / ∗ b c d e – f g {
14. What does the function DO( ) does on a queue? DO (q, q → link);
void DO( ) q → link = p;
{ }
if (!Q is empty) else
{ head = p;
int temp = dequeue ( ); }
DO ( ); When DO(head, head → link) is implemented on sin-
enqueue (temp); gly linked list, the resultant list,
} (A) is a reversal of given list
} (B) remains the same
Programming and Data Structures Test 4 | 3.75

(C) is a circular linked list 23. What will be the post order predecessor of the root
(D) None of these node, in the above resultant tree?
17. Consider the graph below; (A) 26 (B) 21
(C) 28 (D) 9
A B
Linked Answer for Questions 24 and 25:
Consider the circular doubly linked list given below.
D C G
head
a b c
E F

Which of the following orderings are not possible using


depth first search graph traversal: Consider the routine below:
(A) A C G F E D B (B) A D E F C G B struct node
(C) A C G B F E D (D) C G B A D E F {
sturct node *Lptr ;
18. What is the time complexity for attaining maximum
int data;
element from Max heap?
struct node * Rptr;
(A) O(n log n) (B) O(n)
};
(C) O(log n) (D) O(1)
void A ( )
19. Minimum number of nodes in AVL tree of height 5 is {
(with root at height = 1) struct node → t = head → Rptr;
(A) 11 (B) 12 while (t! = head)
(C) 13 (D) 14 {
20. Consider a Binary search Tree ‘T’ in which every node swap (t → Lptr, t → Rptr)
will be having only right child, there are ‘n’ nodes \in tree t = t → Lptr;
‘T’. Time complexity for searching an element will be: }
(B)  log    swap (head → Lptr, head → Rptr);
n
(A) O(log n)
  2  }.

(D) O  
n 24. When A( ) routine is applied on the given list, the head
(C) O(n)
2 Right pointer maps to:
(A) Node containing data field as ‘a’
21. Consider post-order and in-order traversal of a tree:
(B) Node containing data field as ‘b’
POSTORDER :- DCBGFEA
(C) Node containing data field as ‘c’
INORDER :- BDCAFGE
(D) The head pointer points to itself
When tree is constructed from above tree traversals
then what are the leaf nodes? 25. To which node N (pointer) points when the following
(A) D, G (B) C, F operation is performed on the new list formed in the
(C) D, E (D) C, G previous question.
(struct node ∗ N)
Linked Answer for Questions 22 and 23:
N = Head → Rptr → Rptr → Lptr → Lptr → Rptr;
Construct an AVL tree with the elements
(A) Head node
21, 26, 30, 9, 4, 14, 28, 18
(B) Node containing data field as ‘a’
22. What will be the root node for the AVL tree? (C) Node containing data field as ‘b’
(A) 26 (B) 21 (D) Node containing data field as ‘c’
(C) 28 (D) 18

Answer Keys
1. A 2. C 3. B 4. A 5. B 6. C 7. B 8. B 9. A 10. B
11. D 12. A 13. B 14. B 15. D 16. A 17. B 18. D 19. B 20. C
21. A 22. B 23. C 24. C 25. D
3.76 | Programming and Data Structures Test 4

Hints and Explanations


1. Array can be used to represent all the above data struc- 14. Let us consider a queue with 3 elements a, b, c.
tures. Choice (A)
a, b, c
2. Min Heap is a complete Binary tree, with parent node Trace the routine
value less than both the child nodes if they exist.
Temp a a, b, c
Choice (C)
3. Inorder is the traversal of tree which prints data ele- Temp b b, c
ments in an ascending order.
c
Choice (B)
4. Graphs uses adjacency matrix (or) linked representation. Temp c
Choice (A) Enqueue (temp) (3 times)

5. AVL tree is binary search tree with balancing factor as c


0, +1, –1 and search time as O (log n). c, b, a is the resultant Queue.
Choice (B)
Choice (B)
7.
15. Circular queue deletion routine. Choice (D)
16. It reverses the list. Choice (A)
= 5 (for 4 nodes) 17. Let us consider option (B)

D
= 6 (for 5 nodes)
E F
\ For n nodes it will be (n + 1) Null links.
Choice (B) At (F) it can’t reach to vertex (C) as it is not adjacent to
8. 2 stacks required; use one for the Enqueue and the (F). Choice (B)
other for Dequeue. Choice (B) 18. Let us consider a max heap
9. Number of additions in a fibonacci sequence will be fib
(n + 1) – 1. Choice (A) 18

10. For unique pattern of tree either


(pre order + in order) or (post order + in order) are } 16 15
necessary. Choice (B)
11. Traverse the routines on the tree. 2 3 5 8
Choice (D)
12. Traverse the routines on the tree. Choice (A) As the maximum element is at the root. To attain root
element it takes O(1) time. Choice (D)
13. a + b * c/ d ∧ e ∧ f – g
19.
a+b*c/d∧∧ef–g
a+b*c/∧d∧ef–g
a+*bc/∧d∧ef–g
a + / * b c ∧ d ∧ e f –g
+a/*bc∧d∧ef–g
– + a / * b c ∧ d ∧ e f g.
Choice (B) Choice (B)
Programming and Data Structures Test 4 | 3.77

20. Let us consider 5 nodes 22. From the above elements AVL tree will be:
A 21
B
9 28
C
D 4 26 30
14
E
18
To search an element (E) it has to compare 5 elements
\ it is O(n). Choice (C) Choice (B)
21. POST: DCBGFEA 23. Post order for the above tree is 4 18 14 9 26 30 28 21.
IN: BDCAFGE Choice (C)
Consider in order 24. The A( ) routine will reverse the given list
\ Head pointer maps to node containing data field as
BDCAFGE
‘c’.
Choice (C)
A 25.

BDC FGE
c b a
A head

B E Traversing the above list with given operation make to


point to node containing c. Choice (D)
DC FG

B E

C F

D G

Consider in order Choice (A)

You might also like