Java LinkedList MCQ Questions and Answers
Q. What is a linked list in Java?
A. A linear data structure with fixed-size elementsB. A non-linear data structure with dynamic size elements
C. A linear data structure with dynamic size elements
D. A hierarchical data structure with fixed-size elements
Q. What is a node in a linked list?
A. A fixed-size data containerB. A dynamic data container with a value and a reference
C. A hierarchical data structure
D. A functional interface
Q. What is the time complexity of inserting a node at the beginning of a linked list?
A. O(1)B. O(n)
C. O(log n)
D. O(n^2)
Q. What is the time complexity of searching for a node in a linked list?
A. O(1)B. O(n)
C. O(log n)
D. O(n^2)
Q. What is the output of this code snippet?
LinkedList<String> list = new LinkedList<>();
list.add("Apple");
list.add("Banana");
list.addFirst("Mango");
System.out.println(list);
A. [Mango, Apple, Banana]list.add("Apple");
list.add("Banana");
list.addFirst("Mango");
System.out.println(list);
B. [Apple, Mango, Banana]
C. [Mango, Banana, Apple]
D. [Apple, Banana]
Q. What is the purpose of the ListIterator in a linked list?
A. To iterate through the list in reverse orderB. To add elements to the list
C. To remove elements from the list
D. To iterate through the list and modify elements
Q. What is the output of this code snippet?
LinkedList<Integer> list = new LinkedList<>();
list.add(10);
list.add(20);
list.add(30);
System.out.println(list.removeFirst());
System.out.println(list);
A. 10list.add(10);
list.add(20);
list.add(30);
System.out.println(list.removeFirst());
System.out.println(list);
[20, 30]
B. 20
[10, 30]
C. 30
[10, 20]
D. 10
[30, 20]
Q. How do you check if a linked list is empty?
A. list.isEmpty()B. list.size() == 0
C. list.length() == 0
D. list.count() == 0
Q. What is the output of this code snippet?
LinkedList<Integer> list = new LinkedList<>();
list.add(1);
list.add(2);
list.add(3);
list.removeLast();
System.out.println(list);
A. [1, 2]list.add(1);
list.add(2);
list.add(3);
list.removeLast();
System.out.println(list);
B. [2, 3]
C. [1, 3]
D. [1]
Q. What is the time complexity of deleting a node from the middle of a linked list?
A. O(1)B. O(n)
C. O(log n)
D. O(n^2)