Data Structures
Data Structures
✅
b. Queue
c. Both
d. None
2. Which of the following language features in Java generally
✅
corresponds to an Abstract Data Type?
a. Interface
b. Class
c. Objects
d. Primitive Types
3. Which of the following is O(nd)?
a. dn
✅
b. Square root of n
c. Polynomial of degree “d”
d. 3
4. A singly-linked list is used to implement Stack by doing insertions
and deletions at its last node. It maintains a reference to HEAD
and TAIL both. Time complexity of addition and deletion to such
a stack would, respectively, be:
a. O(n2) and O(n)
✅
b. O(1) and O(n)
c. Both will be O(n)
d. O(1) and O(n2)
5. Consider the following code:
public class MyClass{
public static void main(String[] args){
java.util.Stack<Integer> stack = new java.util.Stack<>();
stack.push(1);
System.out.println(stack);
stack.push(2);
System.out.println(stack);
}
}
What will be the output of the above code
a. [1]
[2 1]
✅
b. [1]
[1 2]
c. [1]
[2]
d. Compiler Error
6. Stack overflow occurs when _______ :
a. Number of elements in the stack is 0 and POP is attempted
b. Number of elements in the stack is maximum and POP is
attempted
c. Number of elements in the stack is 0 and PUSH is
attempted
✅
d. Number of elements in the stack is maximum and PUSH is
attempted
7. There exist two functions f(n) and g(n), such that for some
constants c and no the following holds
𝑓(𝑛) ≥ 𝑐. 𝑔(𝑛) ≥ 0 for all n≥n0
Which of the following represents above relationship:
a. g(n) = 𝝮(f(n))
✅
b. f(n) = 𝚹(g(n))
c. f(n) = 𝝮(g(n))
d. g(n) = 𝚹(f(n))
8. You cannot create object of which of the following:
✅
a. Stack<E>
b. Queue<E>
c. ArrayList<E>
d. LinkedList<E>
9. Application of Queue can be seen where:
a. Elements are to be processed in the reverse order of their
insertion
b. Elements are to be processed as per their natural ordering
c. Elements are to be processed in random order
✅
d. Elements are to be processed in the order of their
insertion
✅
b. O(n) and O(1)
c. O(1) and O(1)
d. O(n) and O(n)
11. The difference between peek() and remove() method of
Queue interface is:
a. peek() removes the element that was inserted first while
remove() removes the element that was inserted last
b. peek() removes the element inserted last while remove()
removes the element that was inserted first
c. There is no difference between the two
✅
d. peek() allows us to look at the FRONT element without
removing while remove() actually removes the element
12. The difference between poll() and remove() of Queue<E>
interface is:
✅
a. poll() returns null if the queue is empty while remove()
throws a NoSuchElementException
b. remove() returns null if the queue is empty while poll()
throws a NoSuchElementException
c. poll() does not remove any element form the queue while
remove() does
d. None of the above
13. Which of the following refers to implementation of a STACK
using QUEUE by making POP operation costly:
a. POP = DEQUEUE OPERATION in the QUEUE and TOP of
the STACK is SAME as REAR of the QUEUE
b. PUSH = ENQUEUE OPERATION in the QUEUE and TOP
of the STACK is SAME as FRONT of the QUEUE
c. POP = DEQUEUE OPERATION in the QUEUE and TOP of
the STACK is SAME as FRONT of the QUEUE
✅
d. PUSH = ENQUEUE OPERATION in the QUEUE and TOP
of the STACK is SAME as REAR of the QUEUE
✅
14. Which of the following is correct about HashMap
a. It uses a default Load Factor of 0.75
b. It is an interface in collections package
c. It is a class in collections package
d. It is synchronized
15. Which of the following is correctly matched in the context of
collision handling mechanism:
a. Separate Chaining = Open addressing
b. Linear Probing = Open Hashing
✅
c. Open addressing = Open Hashing
d. Separate Chaining = Open Table
16. Which of the following is NOT a characteristic of a good hash
function?
a. It should avoid collisions
b. It should be fast to compute
✅
c. It should uniformly distribute the keys in the bucket array
d. It should be a polynomial function
17. Which of the following is an interface in Java:
a. Hashtable
b. HashMap
✅
c. HashSet
d. Map
18. Select the correct HashMap declaration for efficiently solving
First Unique Character problem:
a. HashMap<char, int> char_freq = new HashMap<>();
b. HashMap<Character, Double> char_freq = new HashMap<>();
c. HashMap<Integer, Character> char_freq = new HashMap<>();
✅
d. HashMap<Character, Integer> char_freq = new HashMap<>();
19. Which of the following methods is used to insert keys into the
✅
HashMap<K,V>?
a. put(K key, V value)
b. put(K key)
c. put(V key, K value)
d. put(V value)
20. Complexity of searching an element in the map that uses
separate chaining depends on:
✅
a. How uniformly elements are distributed using the Hash
function
b. How many keys are to be mapped
c. How many keys are null
d. None of the above