Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

SBT | TEST | 5 JUNE 2021

 Technical Mcq

1.   When does a regular queue, when implemented with an array of size MAX SIZE, get full?

ans :  Rear = MAX_SIZE -1

 

2.  We define some functions as given below : push( int x ) : This pushes the number x into a predefined
Queue ‘Q’. pop( ) : This pops out( delete ) the last element in the Queue ‘Q’. front( ) : Returns the
number on the top of the Queue ‘Q’.
Now a function “fun( )” is implemented using these three functions. What will be the output of the
function given below?
void fun( )
{
int i=1,j=0;
for(;i<=5;i++)
{
for(j=0;j<i;j++)
{
push( i );
}
int k;
for( k=0; k< i/2 ; k++)
{
pop();
}
printf("%d ", top());

answer : 0 1 2 3 4


3.  A queue stores items in a first-in,first-out(FIFO order) guess the complexity of dequeues.


answer : O(1)


4.  A double-ended queue allows you to add and remove items from both sides of the queue at the same
time. They allow four operations: addFront (adding an item to the front of the queue), addRear (adding
an item to the back of the queue), removeFront (removing an item from the front of the queue), and
removeRear (removing an item from the back of the queue) (removing item from the bottom of the
queue). To implement this data str, you are simply given stacks.


answer : 2


5.  In a circular queue, how do you increment the rear end of the queue?

answer : (rear+1) % CAPACITY


6.  If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order
will they be removed?
 

answer :ABCD


7.

We define some functions as given below : push( int x ) : This pushes the number x into a predefined
Queue ‘Q’. pop( ) : This pops out( delete ) the last element in the Queue ‘Q’. front( ) : Returns the
number on the top of the Queue ‘Q’.
Now a function “fun( )” is implemented using these three functions. What will be the output of the
function given below?
void fun( )
{
int i=1,j=0;
for(;i<=5;i++)
{
for(j=0;j<i;j++)
{
push( i );
push( i\*i );
}
int k;
for( k=0; k< i ; k++)
{
pop( );
}
printf("%d ", top( ));
} }
 

answer :  1 4 9 16 25


8.

To implement a stack, how many queues are required? Consider the case when you don't have access
to any additional data structures, such as arrays or linked lists.
 

answer :  2


9. 

 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?


answer : Reverses the Q


10.  

Consider the following pseudo code. Assume that IntQueue is an integer queue. What does the
function fun do?
void fun(int n)
{
IntQueue q = new IntQueue();
q.enqueue(0);
q.enqueue(1);
for (int i = 0; i < n; i++)
{
int a = q.dequeue();
int b = q.dequeue();
q.enqueue(b);
q.enqueue(a + b);
print(a);
}
}


answer : Prints first n Fibonacci numbers


 ***********************************************************


 

 

Post a Comment

Previous Post Next Post