Dsa Q12
Dsa Q12
struct
{
short P[10];
union
{
short a;
float b;
long z;
} u;
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes
respectively. The memory requirements for variable ‘t’ and ‘u’ ignoring alignment
considerations respectively are _______.
2. The function delete (head, element) is used to delete a node from the linked list by finding the
node value with a given element. The parameter head is the first node of the list. Find the
missing statements A and B in the following “delete” function to delete the node? (Assume all
elements are distinct in the list and the function returns pointers that point to the first node of the
list).
1
x = x.next;
}
}
Assume Node is the structure type with two members: ‘value’ and ‘next’. Identify the node value
printed by the above code if non-empty linked list header is passed to the function find?
(a) First element of the list [i.e., value of the first node]
(b) Second element of the list
(c) Middle element of the list
(d) Last element of the list
4. In delete operation of binary search tree, we need inorder successor (or predecessor) of a node
when a node to be deleted where it has both left and right child. Which of the following is true
about inorder successor needed in delete operation?
(a) Inorder successor is always either leaf node or a node with empty right child.
(b) Inorder successor maybe an ancestor of the node.
(c) Inorder successor is always a leaf node.
(d) Inorder successor is always either a leaf node or a node with empty left child.
2
5. What will be the output printed by the following C program?
void main ( )
{
int x = 1, i, y = 2;
for (i = 0; i < 5; i++)
{
x << 1;
y = x + i;
}
printf(“%d, %d”, x, y);
}
(a) f is a function which takes integer pointer as argument and returns integer.
(b) f is a function which takes integer pointer as an argument and returns address of an integer.
(c) f is a pointer to a function which takes integer pointer as an argument and returns integer.
(d) f is a pointer to a function which takes integer pointer as an argument and returns address of
an integer.
7. Which of the following is NOT true about linked list implementation of queue?
(a) In enqueue operation, if new nodes are inserted at the beginning of linked list, then in
dequeue operation nodes must be removed from end.
(b) In enqueue operation, if new nodes are inserted at the end, then in dequeue nodes must be
removed from the beginning.
(c) Both (a) and (b)
(d) None of the above
3
Which of the following order of elements are inserted into an empty AVL tree, so that it is
possible to get the above AVL tree?
(a) 94, 71, 86, 25, 98, 83, 27, 90 (b) 98, 94, 90, 83, 86, 25, 71, 94
(c) 86, 25, 98, 83, 27, 90, 71, 94 (d) None of these
main ( )
{
extern int i ;
i = 20;
printf (“%d”, i);
}
gate (root)
{
if (root = = null) return 0;
if (root → leftchild = = null && root → rightchild = = null) return 1;
else return (maximum (gate(root → leftchild), gate(root → rightchild)) + 1);
}
4
(d) None of these
11. A 3-ary tree is a tree in which every internal node has exactly 3 children. The number of leaf
nodes in such a tree with 19 internal nodes will be ____________.
void main( )
{
static int i = 5;
if ( – – i)
{
main ( );
printf(“%d”, i);
}
}
13. Consider a two-dimensional array with elements stored in the form of lower triangular
matrix. The elements must be crossed to read A[4, 2] from the array A[–6, …, + 8, – 6, …, + 8]
whose base address 1000 is _________. (Assume elements are stored in row major order).
int main ( )
{
char *str = “Gate2015”
printf (“%d”, ravindra (str));
return 0;
}
5
}
15. The sum of the minimum and maximum number of nodes in the AVL tree of height 5 is
___________. (Assume root node is present at height zero)
int main ( )
{
int x = 016;
printf (“%d”, x);
return 0;
}
If the root of following tree is passed to the above function, what is the level order traversal of
output tree produced by above function? (newNode is a function which creates new node)
6
(a) 2 2 3 3 1 1 (b) 2 2 3 1 3 1
(c) 2 3 2 3 1 1 (d) 2 3 2 3 2 1
18. Which of the following is correct output for the program code given below?
main ( )
{
void pr( );
pr ( );
pr ( );
pr ( );
}
void pr ( )
{
static int i = 1;
printf (“%c”, (65 + i++));
}
20. Consider the following foo function and identify the return value of foo function.
7
return c;
}
21. Which of the following are the number of assignments, number of additions and number of
subtractions respectively required for swapping 2 variables without the help of 3rd variable?
(a) 3, 2, 2 (b) 3, 1, 2
(c) 3, 3, 2 (d) 2, 2, 2
22. Consider the AVL tree T in which left subtree contains half of the maximum number of
nodes possible in the balanced AVL tree of height h and right subtree consists of one 3rd of the
maximum number of nodes possible in AVL tree of height ‘h’.
Assume that tree T may or may not be height balanced at present. What is the total maximum
possible number of nodes in T?
5 5
(a) 6 (2h+1 − 1) − 1 (b) 6 (2h+1 − 1) + 1
3 3
(c) 2 (2h+1 + 1) (d) 2 (2h+1 + 1) − 1
23. The minimum size that an array may require to store a binary tree with ‘n’ nodes is _______.
variable l;
procedure My (K: integer)
begin
K = K + 1;
Print (K);
end
8
procedure R ( )
var l;
begin
l = 5;
My (l);
print (l);
end;
begin
l = 3;
My (l);
R ( );
print (l);
end
Find the output produced by above program using dynamic scoping, and all functions uses call
by value.
(a) 4, 6, 6, 4 (b) 4, 6, 5, 3
(c) 4, 5, 6, 4 (d) 3, 6, 6, 3
struct listnode
{
int data;
struct listnode *next;
};
9
(c) Alternate nodes will be deleted
(d) It reverses the linked list and delete alternate nodes
void f (int n)
{
if (n ≤ 0) return;
else
{
print (n);
f (n – 2);
print (n);
f (n – 1);
}
}
Let f(n) be the number of values printed. What is the number of values printed by above
function?
27. What is the number of additions in the fibonacci series of n which uses following recursive
function.
fib (n) = fib (n – 1) + fib (n – 2)
(a) f (n – 1) + f (n – 2) (b) f (n – 1) + f (n – 2) + n
(c) f (n – 1) + f (n – 2) + 1 (d) f (n – 1) + f (n – 2) + 2n
int x = 0, i;
for (i = 0; i < 10, i++)
if (i%2 && x++)
x += 2;
10
(a) 11 (b) 13
(c) 15 (d) 17
29. Consider the following infix expression which is to be converted to postfix expression using
stack.
(((P + Q) * (R + S)) /T) + (A * (B + C))
The sum of all unique possible heights of stack when converting from infix to postfix is ______.
30. The sum of outputs printed by running the following program is ________.
int main ( )
{
int i;
for (i = 3; i <= 6; i++)
printf(“%d”, f1(i));
}
int f1 (int n)
{
if (n < 2) return n;
else return (f1(n – 1) + f2(n – 2));
}
int f2 (int n)
{
if (n <= 1) return n;
else return (2 * f1 (n – 2) + 1);
}
31. The key 14, 4, 6, 16, 32, 50 in the order are inserted into an initially empty AVL tree. The
total numbers of rotations to make AVL with the given keys are __________. Assume “single
rotation = 1 rotation” and “double rotation = 1 rotation”.
32. Consider the following postorder and Inorder traversals of binary tree.
11
In order: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
The total number of nodes that have height greater than the height of node 6 are ________.
Assume root is at lowest height.
12