Java TreeSet MCQ Questions and Answers
Q. What is the data structure used to implement the LinkedTreeSet in Java?
A. Linked ListB. Array
C. Balanced Binary Search Tree
D. Hash Table
Q. Which interface does LinkedTreeSet implement in Java?
A. SetB. List
C. Queue
D. Deque
Q. What is the time complexity of adding an element to a LinkedTreeSet in Java?
A. O(1)B. O(log n)
C. O(n)
D. O(n log n)
Q. What is the result of calling linkedTreeSet.add(10) if linkedTreeSet contains [5, 8, 15, 3]?
A. [5, 8, 10, 15, 3]B. [5, 8, 15, 10, 3]
C. [5, 8, 15, 3, 10]
D. [3, 5, 8, 10, 15]
Q. How do you iterate over the elements in a LinkedTreeSet?
A. Using a for loopB. Using an iterator
C. Using a while loop
D. All of the above
Q. What is the output of the following code snippet?
LinkedTreeSet<String> colors = new LinkedTreeSet<>(List.of("red", "green", "blue"));
colors.remove("green");
System.out.println(colors);
A. [red, blue]colors.remove("green");
System.out.println(colors);
B. [blue, red]
C. [green, red, blue]
D. [blue, green, red]
Q. What is the time complexity of checking if an element exists in a LinkedTreeSet?
A. O(1)B. O(log n)
C. O(n)
D. O(n log n)
Q. How do you create an empty LinkedTreeSet in Java?
A.LinkedTreeSet<Type> set = new LinkedTreeSet<>();
B.
LinkedTreeSet<Type> set = new LinkedTreeSet<Type>();
C.
LinkedTreeSet<Type> set = new LinkedTreeSet();
D.
LinkedTreeSet set = new LinkedTreeSet();
Q. What is the result of calling linkedTreeSet.ceiling(8) if linkedTreeSet contains [5, 9, 12, 15]?
A. 5B. 9
C. 12
D. null
Q. What is the output of the following code snippet?
LinkedTreeSet<Integer> numbers = new LinkedTreeSet<>(List.of(1, 2, 3, 4, 5));
numbers.descendingSet().forEach(System.out::println);
A. 5 4 3 2 1numbers.descendingSet().forEach(System.out::println);
B. 1 2 3 4 5
C. 1 3 5 2 4
D. 5 3 1 4 2