Stack Quiz
Stack Quiz
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider the following pseudocode:
declare a queue of characters, which is implemeted by circular array of size 6.
while(there are more characters in the word to read)
{read a character
if a character is '*' then
dequeue the queue
else
enqueue the character into the queue
}
How the queue looks like after processing the input "How***AreYou***"?
(4)
(2)
(1)
(3)
Feedback
The correct answer is: (1)
Question 2
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Specify the correct implementation of dequeue() method of a queue. This queue uses
the object a of java.util.LinkedList for storing data and the head of the list is treated as
the head of the queue. (Choose the most suitable one)
Question 2Select one:
Object dequeue()
{ if (isEmpty()) return(null);
return(a.removeFirst();
}
void dequeue(Object x)
{ if (isEmpty()) return(null);
a.remove(a.size()-1);
}
void dequeue(Object x)
{ if (isEmpty()) return;
a.remove(a.size()-1);
}
Object dequeue()
{ if (isEmpty()) return(null);
return(a.removeLast());
}
Feedback
The correct answer is: Object dequeue()
{ if (isEmpty()) return(null);
return(a.removeFirst();
}
Question 3
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Suppose we are implementing a queue using a singly linked list where the the end of the list is
treated as the end of the queue.
Specify the correct implementation of enqueue() method of the queue. (Choose the
most suitable one)
Question 3Select one:
void enqueue(Object x)
{ Node p = new Node(x);
p.next = null;
if(isEmpty()) head = tail = p;
else { tail.next = p; tail = p; }
}
void enqueue(Object x)
{ Node p = new Node(x);
p.next = null; tail.next = p; tail = p;
}
void enqueue(Object x)
{ Node p = new Node(x);
p.next = null;
if(isEmpty()) head = tail = p; else tail.next = p;
}
Feedback
The correct answer is: void enqueue(Object x)
{ Node p = new Node(x);
p.next = null;
if(isEmpty()) head = tail = p;
else { tail.next = p; tail = p; }
}
Question 4
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In the array implementation, dequeuing can be executed in constant time O(n)
Question 4Answer
True
False
Feedback
The correct answer is 'False'.
Question 5
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What does "stack underflow" refer to?
a.
index out of bounds exception
b.
accessing item from an undefined stack
c.
adding items to a full stack
d.
removing items from an empty stack
Feedback
Your answer is correct.
The correct answer is: removing items from an empty stack
Question 6
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following real world scenarios would you associate with a stack data structure?
a.
offer services based on the priority of the customer
b.
people standing in a line to be serviced at a counter
c.
all of the mentioned
d.
piling up of chairs one above the other
Feedback
Your answer is correct.
The correct answer is: piling up of chairs one above the other
Question 7
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider the following pseudocode:
declare a queue of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
dequeue and write the dequeued character to the screen
else
enqueue the character into the queue
}
What is written to the screen for the input "Goo**dAft***erno*on" ?
GoodAT
GoodAE
fAdooG
GoodAf
Feedback
The correct answer is: GoodAf
Question 8
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following about queue is true:
Question 8Select one:
A queue is a structure in which both ends are used for adding new elements and removing
them.
Question 9
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Specify the correct implementation of dequeue() method of a queue. This queue uses
the object a of java.util.ArrayList for storing data and the position 0 of the list is treated
as the front of the queue. (Choose the most suitable one)
Question 9Select one:
Object dequeue()
{ if (isEmpty()) return(null);
return(a.remove(0));
}
void dequeue(Object x)
{ if (isEmpty()) return(null);
a.remove(a.size()-1);
}
Object dequeue()
{ if (isEmpty()) return(null);
return(a.remove(a.size()));
Object dequeue()
{if (isEmpty()) return;
return(a.remove(a.size()-1));
}
Feedback
The correct answer is: Object dequeue()
{ if (isEmpty()) return(null);
return(a.remove(0));
}
Question 10
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In linked list implementation of a queue, where does a new element be inserted?
a.
At the head of link list
b.
At the centre position in the link list
c.
At the tail of the link list
d.
None of the mentioned
Feedback
Your answer is correct.
The correct answer is: At the tail of the link list
Question 11
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Select the most correct statement:
A doubly linked list is better choice than a singly linked list for queue implementation.
Naturally a singly linked list is a good choice for queue implementation because both enque
and dequeue actions are constant time O(1).
Question 12
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Select the statement that is most correct.
Which of the following applications may not use a stack?
Question 12Select one:
Multi-programming.
Question 13
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop the stack
else
push the character into the stack
}
while(the stack is not empty)
pop and write the poped character to the screen
gnMoG
gnoMo
gnMoo
GoMng
Feedback
The correct answer is: gnMoG
Question 14
Correct
Mark 1.00 out of 1.00
Flag question
Question text
The operation for removing and returning the element of the queue is traditionally
called:
Question 14Select one:
peek
delete
dequeue
remove
Feedback
The correct answer is: dequeue
Question 15
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In linked list implementation of a queue, front and rear pointers are tracked (front = head,
rear = tail). Which of these pointers will change during an insertion into a NONEMPTY
queue?
a.
None of the mentioned
b.
Only front pointer
c.
Both front and rear pointer
d.
Only rear pointer
Feedback
Your answer is correct.
The correct answer is: Only rear pointer
Question 16
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following stack operations could result in stack underflow (become
empty)?
Question 16Select one:
isEmpty
pop
push
Feedback
The correct answer is: pop
Question 17
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Select correct statement:
Question 17Select one:
Question 18
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following array position will be occupied by a new element being pushed for a
stack of size N elements(capacity of stack > N).
b.
S[1].
c.
S[N].
d.
S[0].
Feedback
Your answer is correct.
The correct answer is: S[N].
Question 19
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In the doubly linked list implementation, dequeuing can be executed in constant time
O(1)
Question 19Answer
True
False
Feedback
The correct answer is 'True'.
Question 20
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In linked list implementation of a queue, front and rear pointers are tracked (front = head,
rear = tail). Which of these pointers will change during an insertion into EMPTY queue?
b.
Only rear pointer
c.
None of the mentioned
d.
Only front pointer
Feedback
Your answer is correct.
The correct answer is: Both front and rear pointer
Question 21
Correct
Mark 1.00 out of 1.00
Flag question
Question text
The operation for adding an entry to a stack is traditionally called:
Question 21Select one:
insert
add
append
push
Feedback
The correct answer is: push
Question 22
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In the array implementation, enqueuing can be executed in constant time O(1)
Question 22Answer
True
False
Feedback
The correct answer is 'True'.
Question 23
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following queue operations could result in queue underflow (become
empty)?
Question 23Select one:
enqueue
dequeue
isEmpty
Feedback
The correct answer is: dequeue
Question 24
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Specify the correct implementation of pop() method of a stack of Integers. This stack
uses the object a of java.util.LinkedList class for storing data and the end of the list is
treated as the top of the stack. (Choose the most suitable one)
Question 24Select one:
Integer pop()
{ if (isEmpty()) return(null);
return((Integer) a.removeLast();
}
void pop(Integer x)
{ if (isEmpty()) return(null);
a.remove(a.size()-1);
}
Integer pop()
{if (isEmpty()) return;
return((Integer) a.remove(a.size()-1));
}
Integer pop()
{ if (isEmpty()) return(null);
return((Integer)
a.remove(a.size()));
}
Feedback
The correct answer is: Integer pop()
{ if (isEmpty()) return(null);
return((Integer) a.removeLast();
}
Question 25
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In the doubly linked list implementation, enqueuing can be executed in constant time
O(1).
Question 25Answer
True
False
Feedback
The correct answer is 'True'.
Question 26
Correct
Mark 1.00 out of 1.00
Flag question
Question text
The operation for removing and returning the top element of the stack is traditionally called:
Question 26Select one:
peek
pop
remove
delete
Feedback
The correct answer is: pop
Question 27
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider the following pseudocode:
declare a stack of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
pop and write the poped character to the screen
else
push the character into the stack
}
What is written to the screen for the input "Good**Mor*ni***ng" ?
Question 27Select one:
dorinM
dorioM
dorinG
dorino
Feedback
The correct answer is: dorino
Question 28
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What is the time complexity of pop() operation when the stack is implemented using an
array?
a.
O(nlogn)
b.
O(1)
c.
O( n)
d.
O(logn)
Feedback
Your answer is correct.
The correct answer is: O(1)
Question 29
Correct
Mark 1.00 out of 1.00
Flag question
Question text
What does "stack overflow" refer to?
a.
removing items from an empty stack
b.
adding items to a full stack
c.
accessing item from an undefined stack
d.
index out of bounds exception
Feedback
Your answer is correct.
The correct answer is: adding items to a full stack
Question 30
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Suppose we are implementing a queue using a singly linked list where the the head of the list is
treated as the head of the queue.
Specify the correct implementation of dequeue() method of the queue. (Choose the
most suitable one)
Question 30Select one:
Object dequeue()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==null) tail=null;
return(p.info);
}
Object dequeue()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==tail) tail=null;
return(p.info);
}
Object dequeue()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
return(p.info);
}
Feedback
The correct answer is: Object dequeue()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==null) tail=null;
return(p.info);
}
Question 31
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider the following pseudocode:
declare a queue of characters
while(there are more characters in the word to read)
{read a character
if a character is '*' then
dequeue the queue
else
enqueue the character into the queue
}
while(the queue is not empty)
dequeue and write the dequeued character to the screen
What is written to the screen for the input "HowAre**You**To**Day" ?
Question 31Select one:
ouToDay
eYouToDa
yaDoTuoY
YouToDay
Feedback
The correct answer is: YouToDay
Question 32
Correct
Mark 1.00 out of 1.00
Flag question
Question text
In linked list implementation of a queue, from where is the item dequeued?
a.
At the tail of the link list
b.
None of the mentioned
c.
At the head of link list
d.
At the centre position in the link list
Feedback
Your answer is correct.
The correct answer is: At the head of link list
Question 33
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Consider these functions:
push() : push an element into the stack
pop() : pop the top-of-the-stack element
top() : returns the item stored in top-of-the-stack-node
What will be the output after performing these sequence of operations
push(20);
push(4);
top();
pop();
pop();
push(5);
top();
Question 33Select one:
a.
20
b.
5
c.
4
d.
stack underflow
Feedback
Your answer is correct.
The correct answer is: 5
Question 34
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Suppose we are implementing a stack using a singly linked list where the head of the list is
treated as the top of the stack.
Specify the correct implementation of pop() method of the stack. (Choose the most
suitable one)
Object pop()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==null) tail=null;
return(p.info);
}
Object pop()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
return(p.info);
}
Object pop()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==tail) tail=null;
return(p.info);
}
Feedback
The correct answer is: Object pop()
{ if(isEmpty()) return(null);
Node p = head; head=head.next;
if(head==null) tail=null;
return(p.info);
}
Question 35
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Select the statement that is most correct.
Which of the following applications may not use a queue?
Question 35Select one:
Multi-programming.
Feedback
The correct answer is: Undo sequence in a text editor.
Question 36
Correct
Mark 1.00 out of 1.00
Flag question
Question text
Which of the following properties is associated with a queue?
a.
None of the mentioned
b.
First In Last Out
c.
First In First Out
d.
Last In First Out
Feedback
Your answer is correct.
The correct answer is: First In First Out
Question 37
Correct
Mark 1.00 out of 1.00
Flag question
Question text
The operation for adding an entry to a queue is traditionally called:
Question 37Select one:
add
enqueue
append
insert
Feedback
The correct answer is: enqueue