LearnFrenzy
Sign in Take a free test

Data Structures in Java · Exercise 1 of 4

Data Structures in Java Data Structures in Java MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on data structures in Java: Big-O, dynamic arrays, linked lists, stacks, queues, circular queues, heaps, binary search trees, hash tables, graphs and tries. Pick an option to check your answer instantly.

Question 11 Medium

Why does the JDK documentation recommend ArrayDeque over java.util.Stack for a stack?

A Stack cannot store objects
B Stack is synchronized and extends Vector, so it is slower and exposes index-based methods
C ArrayDeque allows null elements
D Stack has no pop method
Question page & discussion
Question 12 Medium

In what order does a for-each loop visit the elements of a PriorityQueue?

A Ascending order
B Insertion order
C No particular order (the internal heap array order)
D Descending order
Question page & discussion
Question 13 Hard

A hash table resolves a collision by trying the next slot, then the next, until it finds a free one. What is this technique called?

A Separate chaining
B Open addressing (linear probing)
C Rehashing into a tree
D Double buffering
Question page & discussion
Question 14 Medium

How much memory does an adjacency list need for a graph with V vertices and E edges?

A O(V²)
B O(V + E)
C O(E²)
D O(V × E)
Question page & discussion
Question 15 Medium

A trie holds n words. What is the cost of checking whether a word of length L is present?

A O(n)
B O(log n)
C O(L)
D O(n × L)
Question page & discussion
Question 16 Easy

In an array-based circular queue of size capacity, how is the next tail index computed?

A tail + 1
B (tail + 1) % capacity
C tail * 2
D (tail - 1) % capacity
Question page & discussion
Question 17 Medium

You already hold a reference to a node in a doubly linked list. What does it cost to remove that node?

A O(1)
B O(log n)
C O(n)
D O(n²)
Question page & discussion
Question 18 Medium

What is the worst-case time of PriorityQueue.offer with n elements already in the queue?

A O(1)
B O(log n)
C O(n)
D O(n log n)
Question page & discussion
Question 19 Hard

Which technique detects a cycle in a singly linked list using only O(1) extra memory?

A Store visited nodes in a HashSet
B Floyd's slow and fast pointers
C Sort the nodes first
D Reverse the list twice
Question page & discussion
Question 20 Hard

new PriorityQueue<>(collection) builds the heap with bottom-up heapify. What is its time complexity?

A O(n)
B O(n log n)
C O(log n)
D O(n²)
Question page & discussion
Up next · Exercise 2Data Structures in Java Output Questions20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links