A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

31. The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is
a. 284
b. 213
c. 142
d. 71
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).142

32. A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.
If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
a. 6
b. 4
c. 3
d. 2
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).3

33. Consider the following C program:

#include
#define EOF -1
void push (int); /* push the argument on the stack */
int pop (void); /* pop the top of the stack */
void flagError ();
int main ()
{ int c, m, n, r;
while ((c = getchar ()) != EOF)
{ if (isdigit (c) )
push (c);
else if ((c == '+') || (c == '*'))
{ m = pop ();
n = pop ();
r = (c == '+') ? n + m : n*m;
push (r);
}
else if (c != ' ')
flagError ();
}
printf("% c", pop ());
}

What is the output of the program for the following input ? 5 2 * 3 3 2 + * +
a. 15
b. 25
c. 30
d. 150
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).25

34. Suppose a stack is to be implemented with a linked list instead of an array. What would be the effect on the time complexity of the push and pop operations of the stack implemented using linked list (Assuming stack is implemented efficiently)?
a. O(1) for insertion and O(n) for deletion
b. O(1) for insertion and O(1) for deletion
c. O(n) for insertion and O(1) for deletion
d. O(n) for insertion and O(n) for deletion
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).O(1) for insertion and O(1) for deletion

35. Consider n elements that are equally distributed in k stacks. In each stack, elements of it are arranged in ascending order (min is at the top in each of the stack and then increasing downwards). Given a queue of size n in which we have to put all n elements in increasing order. What will be the time complexity of the best known algorithm?
a. O(n logk)
b. O(nk)
c. O(n^2)
d. O(k^2)
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).O(n logk)

36. Following is C like pseudo code of a function that takes a Queue as an argument, and uses a stack S to do processing.

void fun(Queue *Q)
{
    Stack S;  // Say it creates an empty stack S
 
    // Run while Q is not empty
    while (!isEmpty(Q))
    {
        // deQueue an item from Q and push the dequeued item to S
        push(&S, deQueue(Q));
    }
 
    // Run while Stack S is not empty
    while (!isEmpty(&S))
    {
      // Pop an item from S and enqueue the poppped item to Q
      enQueue(Q, pop(&S));
    }
}

What does the above function do in general?
a. Removes the last from Q
b. Keeps the Q same as it was before the call
c. Makes Q empty
d. Reverses the Q
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).Reverses the Q

37. Which one of the following is an application of Queue Data Structure?
a. When a resource is shared among multiple consumers.
b. When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes
c. Load Balancing
d. All of the above
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).All of the above

38. How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.
a. 1
b. 2
c. 3
d. 4
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).2

39. How many queues are needed to implement a stack. Consider the situation where no other data structure like arrays, linked list is available to you.
a. 1
b. 2
c. 3
d. 4
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).2

40. A priority queue can efficiently implemented using which of the following data structures? Assume that the number of insert and peek (operation to see the current highest priority item) and extraction (remove the highest priority item) operations are almost same.
a. Array
b. Linked List
c. Heap Data Structures like Binary Heap, Fibonacci Heap
d. None of the above
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).Heap Data Structures like Binary Heap, Fibonacci Heap

Page 4 of 12