Font size
Worksheetstmp-Queue and Stack
Total questions: 87
Worksheet time: 3575secs
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?
ABCD
DCBA
DCAB
ABDC
In linked list implementation of a queue, the important condition for a queue to be empty is?
FRONT is null
REAR is null
LINK is empty
None of the mentioned
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.
1
2
3
4
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.
1
2
3
4
Which of the following is true about linked list implementation of queue?
In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.
In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning.
Both of the above
None of the above
Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are
Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR
Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT
Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.
What is the worst case time complexity of a sequence of n MultiDequeue() operations on an initially empty queue?
O(n)
O(n+k)
O(nk)
O(n^2)
Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?
A queue cannot be implemented using this stack.
A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.
A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.
A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.
Let Q denote a queue containing sixteen numbers and S be an empty stack. Head(Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.
The maximum possible number of iterations of the while loop in the algorithm is
16
32
64
256
Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing.
What does the above function do in general?
Prints binary representation of n in reverse order
Prints binary representation of n
Prints the value of Logn
Prints the value of Logn in reverse order
The following postfix expression with single digit operands is evaluated using a stack:
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is evaluated are:
6,1
5,7
3,2
1,5
If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack, the sequence of popped out values
2,2,1,1,2
2,2,1,2,2
2,1,2,2,1
2,1,2,2,2
The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is
A
B
C
D
E
Consider the following operations performed on a stack of size 5 : Push (a); Pop() ; Push(b); Push(c); Pop(); Push(d); Pop();Pop(); Push (e) Which of the following statements is correct?
Underflow occurs
Stack operations are performed smoothly
Overflow occurs
None of the above
Which of the following is not an inherent application of stack?
Implementation of recursion
Evaluation of a postfix expression
Job scheduling
Reverse a string
If you're building a system for online voting where each vote is unique, but the order in which votes are cast doesn't matter, which interface would be the best pick?
List Interface
Set Interface
Queue Interface
Map Interface
When designing an application to manage a restaurant's waiting list where customers are served based on their arrival, which interface would be best suited?
List Interface
Set Interface
Queue Interface
Map Interface
What distinguishes the LinkedHashSet class from the HashSet class in the Java Collections framework?
LinkedHashSet maintains insertion order
LinkedHashSet allows duplicate values
LinkedHashSet uses a tree structure for storage
LinkedHashSet provides faster access times
If you need a data structure that can be accessed and modified by multiple threads safely, which class would you select?
ArrayList Class
Vector Class
LinkedList Class
HashSet Class
When you need a resizable array with efficient random access, which class is the most relevant choice?
LinkedList Class
ArrayList Class
HashSet Class
TreeSet Class
If you need a collection that ensures a first-in-first-out (FIFO) behavior, which interface would be the best fit?
Set Interface
List Interface
Map Interface
Queue Interface
Which interface ensures element order based on their natural ordering or by a provided comparator?
Set Interface
List Interface
SortedSet Interface
Queue Interface
When designing a data structure that allows duplicates, maintains insertion order, and provides random access, which interface is the most suitable?
Set Interface
LinkedHashSet Class
List Interface
TreeSet Class
Which interface is best suited to represent a group of objects as a single unit?
List Interface
Set Interface
Collection Interface
Queue Interface
What's the primary advantage of using the SortedSet Interface over the standard Set Interface?
It allows duplicates
It processes items in a FIFO manner
It sorts items based on their natural order or a defined comparator
It allows random access
Which of the following statements are true with respect to sets as objects of Hashset?
Set is always an ordered group of objects.
Set allows duplicate objects.
Set does not allow duplicate objects.
Set supports iterators.
Which of the following statements are correct in relation to collections in Java?
A collection can have objects of different types in it.
The Collection is a class.
A collection can have only one type of object in it.
A collection is same as a standard array.
Which of the following interfaces declares a core method that all collections will have?
EventListener
Comparator
Set
Collection
Which of the following statements are correct with respect to a Map in Java?
A map can have iterators for accessing its elements.
The elements of a map are accessed by the respective keys.
Maps are the same as a SortedSet.
None of these.
Which of the following interfaces are not a part of the Java's Collection Framework?
SortedList
Set
SortedMap
List
Which of the following statements are correct with respect to a List in Java?
A List is implemented in the "first-in, first-out" (FIFO) order.
A List is implemented in the "first-in, last-out" (FILO) order.
Lists support duplicate items.
None of these.
Which of the following interfaces must contain a unique element?
List
Set
Array
Collection
Which of the following method deletes all the elements from invoking (calling) collections?
reset()
clear()
delete()
refresh()
Which of the following statements are true with respect to a stack?
A Stack is implemented in the "first-in, first-out" (FIFO) order.
A Stack is implemented in the "first-in, last-out" (FILO) order.
A Stack supports random access.
None of these.
Which of the following classes implement the Queue interface?
HashSet
TreeSet
LinkedList
None of these
What is Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
What will be the output of the Java program?
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these exceptions is thrown by remover() method?
IOException
SystemException
ObjectNotFoundExeception
IllegalStateException
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of these interface declares core method that all collections will have?
Collection
EventListner
Comparator
Set
List
Which of these is an incorrect form of using method max() to obtain maximum element?
max(Collection c)
max(Collection c, Comparator comp)
max(Comparator comp)
max(List c)
Which of these methods can convert an object into a List?
SetList()
ConvertList()
CopyList()
singletonList()
Which of these is true about unmodifiableCollection() method?
unmodifiableCollection() returns a collection that cannot be modified.
unmodifiableCollection() method is available only for List and Set.
unmodifiableCollection() is defined in Collection class.
None of the mentioned.
Which of these is static variable defined in Collections?
EMPTY_SET
EMPTY_LIST
EMPTY_MAP
All of the mentioned
What implementation of Iterator can traverse a collection in both directions?
Iterator
ListIterator
SetIterator
MapIterator
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
What will be output of given code
a followed by concurrentModification Exception
a b c
a b
a c
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.
Which interface provides that capability?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.
Which interface provides that capability?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
The default capacity of a Vector is:
10
12
8
0
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
Find the output
public class TreeMapTest {
public static void main(String args[]) {
Map<Integer, String> m = new TreeMap<Integer, String>();
m.put(11, "audi");
m.put(null, null);
m.put(11, "bmw");
m.put(null, "ferrari");
System.out.println(m.size());
System.out.println(m);
}
Nullpointer exception
compiler error
2
Null value
public class MyClass {
public static void main(String args[]) {
Map<String, String> hashMap = new HashMap<String, String>();
hashMap.put(new String("a"), "audi");
hashMap.put(new String("a"), "ferrari");
System.out.println(hashMap);
}
}
a=audi
a=audi
a=ferrari
a=ferrari
Run time Error
Deque and Queue are derived from
Abstract class
Collection
Abstactcollection
List
What will be output of given code
1 2 3
1 followed by exception
Compile time error
run time error
Which is best suited to a multi-threaded environment?
WeakHashMap
Hashtable
HashMap
ConcurrentHashMap
TreeMap implements?
Dictionary
HashMap
AbstractMap
NavigableMap
Which of these is synchronized?
TreeMap
HashMap
Hashtable
All of the above
TreeMap
doesn't allow null key
allow many null values
Both
allow many null key
How can you sort given HashMap on basis of values
Implement Comparator interface and override its compare method
It is not possible
Implement Comparator interface and override its compareTo method
Implement Comparator interface and override its comparable method
What does Collections.sort internally uses when number of elements are less than 7?
Insertion sort
Merge sort
Quick sort
None
What does Collections.sort internally uses when number of elements are greater than 7?
Insertion sort
Merge sort
Quick sort
None
In linked list implementation of a queue, where does a new element be inserted?
At the head of link list
At the centre position in the link list
At the tail of the link list
None of the mentioned
In linked list implementation of a queue, the important condition for a queue to be empty is?
FRONT is null
REAR is null
LINK is empty
None of the mentioned
In a circular queue, how do you increment the rear end of the queue?
rear++
(rear+1) % Number of Item
(rear % Number of Item)+1
rear–
Which is the application of a queue?
CPU allocation
Sharing printer
Graph traversal
All
If REAR, FRONT are the queue variables, then identify correct statement while inserting a value
FRONT=1
REAR=REAR+1
REAR=REAR-1
FRONT=FRONT-1
If elements are inserted in the order -10,-2,-3,4,-1,6 then to delete value -3 how many dequeue operations are required?
(a)
Time complexity of enqueue is
O(n)
O(1)
O(nlogn)
O(logn)
Number of queues required to implement a stack is
1
2
3
cannot be implemented
A circular queue is implemented using an array of size 10. The array index starts with 0, front is 6, and rear is 9. The insertion of next element takes place at the array index
7
9
10
0
In linked list implementation of a queue, where does a new element be inserted?
At the head of link list
At the centre position in the link list
At the tail of the link list
None of the mentioned
In linked list implementation of a queue, from where is the item deleted?
At the head of link list
At the centre position in the link list
At the tail of the link list
None of the mentioned
Let the following circular queue can accommodate maximum six elements with the following data
front = 2 rear = 4
queue = _______; L, M, N, ___, ___
What will happen after ADD O operation takes place?
front = 2 rear = 5
queue = ______; L, M, N, O, ___
front = 3 rear = 5
queue = L, M, N, O, ___
front = 3 rear = 4
queue = ______; L, M, N, O, ___
front = 2 rear = 4
queue = L, M, N, O, ___
What is the reason for using a "circular queue" instead of a regular one?
running time of enqueue() is improved
reuse empty spaces
you can traverse all the elements more efficiently
none of the above
One difference between a queue and a stack is:
Queues require dynamic memory, but stacks do not
Stacks require dynamic memory, but queues do not.
Queues use two ends of the structure; stacks use only one.
Stacks use two ends of the structure, queues use only one.
If the numbers 5, 10, 3, 42 are enqueued onto a queue in that order, what does dequeue return?
5
10
3
42
The essential condition which is checked before insertion in a linked queue is?
Underflow
Overflow
Front value
Rear value
A queue of characters currently contained A,B,C,D What would be the contents of queue after the following operationDELETE, ADD W, ADD X, DELETE, ADD Y.
A,B,C,W,Y
A,B,C,D,W
C,D,W,X,Y
W,Y,X,C,D
If front=rear ,then the queue is?
full
undeflow
overflow
empty
Insertion operation is done at only one end and
deletion operation is done at both the ends
Input Restricted Queue
Output Restricted Queue
Priority Queue
None of these
Deletion operation is done at only one end and insertion
operation is done at both the ends
Input Restricted Queue
Output Restricted Queue
Priority Queue
None of these
