Data Structure and Algorithms using Java Week 2 Nptel Answers

Are you looking for the Data Structure and Algorithms using Java Week 2 NPTEL Answers ? You’ve come to the right place! We provide accurate and detailed solutions to help you with your Week 2 assignments in this course.


Image for Data Structure and Algorithms using Java Week 2 Nptel  Answers
Data Structure and Algorithms using Java Week 2 Nptel Answers

Data Structure and Algorithms using Java Week 2 Nptel Answers (July-Dec 2025)


Question 1. Which of the following interfaces are NOT descendants of java.util.Collection?
a) java.util.SortedMap
b) java.util.Set
c) java.util.SortedSet
d) java.util.Queue

View Answers


Question 2. Which of the following statements is not true for Java?
a) Java supports the basic data structures like arrays and linked lists.
b) Java does not support complex data structures.
c) Java provides built-in support for data structures through the Java Collections Framework.
d) A collection in Java is any group of objects.

View Answers


Question 3. Which of the following are valid ways to declare collection-based data structures in Java?
a) List<Integer> list = new ArrayList<>();
b) Map<string> map = new HashMap<>();
c) Set<String> set = new HashSet<>();
d) Queue<Integer> queue = new PriorityQueue<>();

View Answers


Question 4. What will be the output of the following code snippet?

import java.util.*;
public class TestQ4 {
  public static void main(String[] args) {
    List<Number> list = new ArrayList<>();
    list.add(2);
    list.add(2.0);
    System.out.println(list);
  }
}

a) [2, 2.0]
b) [20, 2]
c) Compilation Error – can’t mix int and double
d) Runtime Error – incompatible types

View Answers


Question 5. Which of the following operations are NOT supported by the SortedSet interface?
a) Adding elements
b) Sorting elements explicitly
c) Retrieving by index
d) Removing elements

View Answers


Question 6. What is the error in the following code?

import java.util.*;
class Test {
  public static void main(String[] args) {
    HashSet<String> set = new HashSet<>();
    set.add("apple");
    set.add("banana");
    set.add("apple");
    System.out.println(set);
  }
}

a) Compilation Error
b) Runtime Error – duplicate element
c) No error; duplicate is ignored
d) Output always matches insertion order

View Answers


Question 7. Which of the following are part of the Map framework in Java?
a) TreeMap
b) HashMap
c) LinkedList
d) Hashtable

View Answers


Question 8. What is the output of the following code?

import java.util.*;
public class TestQ8 {
  public static void main(String[] args) {
    SortedMap<Integer, String> map = new TreeMap<>();
    map.put(3, "Apple");
    map.put(1, "Banana");
    map.put(4, "Cherry");
    map.put(2, "Date");
    System.out.println(map);
  }
}

a) {3=Apple, 1=Banana, 4=Cherry, 2=Date}
b) {1=Banana, 2=Date, 3=Apple, 4=Cherry}
c) {Apple=3, Banana=1, Cherry=4, Date=2}
d) Compilation Error

View Answers


Question 9. Which of the following is NOT a legacy class or interface in Java?
a) Hashtable
b) Enumeration
c) Queue
d) Vector

View Answers


Question 10. What is the output of the following code?

import java.util.*;
public class TestQ10 {
  public static void main(String[] args) {
    Vector<String> vec = new Vector<>();
    vec.add("A");
    vec.add("B");
    vec.remove(1);
    vec.add("C");
    System.out.println(vec);
  }
}

a) [A, C]
b) [B, C]
c) [A, B, C]
d) [A]

View Answers


Data Structure and Algorithms using Java Week 2 Nptel Answers (July-Dec 2024)

Course Link: Click Here


Q1.Which of the following classes is part of the Java Collections Framework and implements the List interface?
a. HashSet
b. LinkedList
c. TreeMap
d. PriorityQueue

Answer: b. LinkedList


Q2. Which of the following is True in the case of Java Collection Framework(JCF)?
a. JCF provides mid-performance software encoding
b. Extending and/or adapting a collection is easy and not flexible with JCF
c. The JCF is consist of : Collections and Facilities
d. The JCF doesn’t allow different types of collections to work with a high degree of interoperability.

Answer: c. The JCF is consist of : Collections and Facilities


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 2 Nptel Assignment Answers


Q3. Which of the following interfaces is not part of the Java Collections Framework?
a. Set
b. Queue
c. Map
d. Stream

Answer: d. Stream


Q4. Which of the following statements is true regarding legacy classes in the Java Collections Framework?
a. All legacy classes have been deprecated and should no longer be used.
b. Legacy classes are fully compatible with the Java Collections Framework and have not been deprecated.
c. Legacy classes are part of the Java Collections Framework and implement all collection interfaces.
d. Legacy classes are new additions to the Java Collections Framework introduced in Java 8.

Answer: b. Legacy classes are fully compatible with the Java Collections Framework and have not been deprecated


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 2 Nptel Assignment Answers


Q5. Which interface extends SortedSet to handle retrieval of elements based on closest-match?
a. Set
b. SortedSet
c. NavigableSet
d. Collection

Answer: c. NavigableSet


Q6.Which of the following statements is/are incorrect for Java Collection Framework (JCF)?
a. Vector is similar to. ArrayList, which represents a dynamic array
b. Stack is a subclass of Vector that implements a standard last-in,first-out stack.
c. Unlike HashMap, Hashtable doesn’t store Key/value pairs.
d. Class Properties are used to maintain a list of values in which both key and value are String.

Answer: c. Unlike HashMap, Hashtable doesn’t store Key/value pairs.


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 2 Nptel Assignment Answers


Q7. In the Java Collections Framework (JCF), the Properties class extends __?
a. HashMap
b. Hashtable
c. TreeMap
d. HashSet

Answer: b. Hashtable


Q8. In the Java Collections Framework, TreeMap extends which class and implements which interface?
a. Extends HashMap; implements sortedMap
b. Extends AbstractMap; implements NavigableMap
c. Extends Hashtable; implements TreeSet
d. Extends LinkedHashMap; implements List

Answer: b. Extends AbstractMap; implements NavigableMap


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 2 Nptel Assignment Answers


Q9. In the Queue interface of the Java Collections Framework, what do the peek() and poll() methods respectively do?
a. Both methods retrieve and remove the head of the queue.
b. Both methods retrieve but do not remove the head of the queue.
c. peek() retrieves and removes the head of the queue, while poll() retrieves but does not remove the head of the queue.
d. peek() retrieves but does not remove the head of the queue, while poll() retrieves and removes the head of the queue.

Answer: d. peek() retrieves but does not remove the head of the queue, while poll() retrieves and removes the head of the queue.


Q10.Which of these interface handle sequences?
a. Set
b. Array
c. List
d. Collection

Answer: c. List


For answers or latest updates join our telegram channel: Click here to join

These are Data Structure and Algorithms using Java Week 2 Nptel Assignment Answers

Want all Weeks of Data Structure and Algorithms using Java Nptel Assignment Answers : Click here

For answers to additional Nptel courses, please refer to this link: NPTEL Assignment Answers