NPTEL Data Structure and Algorithms using Java Week 9 Assignment Answers 2024

Sanket
By Sanket

NPTEL Data Structure and Algorithms using Java Week 9 Assignment Answers 2024

1. Which of the following statements about the Set interface in Java is FALSE?

a. The Set interface is present in the java.util package.
b. The Set interface extends the Collection interface.
c. A Set represents an ordered collection of elements.
d. A Set allows the storage of a null element.

Answer :- For Answers Click Here 

2. Which of the following declarations is/are Incorrect?

a. Set s1 = new HashSet();
b. Set s2 = new LinkedHashSet();
c. Set s3 = new TreeSet();
d. Set s4 = HashSet();

Answer :- For Answers Click Here 

3. What is the default initial capacity of a HashSet in Java, and why might you specify a different capacity in the constructor?

a. 10, to optimize memory usage
b. 16, to improve search efficiency
c. 32, to store large datasets
d. 16, to avoid rehashing if the Set will contain more elements

Answer :- For Answers Click Here 

4. Which of the following is not a way to iterate over a HashSet in Java?

a. Using a simple for-each loop
b. Using the iterator() method
c. Using iterator() and forEachRemaining() method
d. Using a traditional for loop with an index

Answer :- 

5. What is the key difference between a HashSet and a LinkedHashSet in Java?

a. HashSet is faster than LinkedHashSet for all operations
b. HashSet maintains insertion order, while LinkedHashSet does not
c. LinkedHashSet maintains the order of elements based on insertion, while HashSet does not
d. LinkedHashSet allows duplicate elements, while HashSet does not

Answer :- 

6. Which of the following statements about the TreeSet class in Java is true?

a. TreeSet stores elements in the order they are inserted
b. TreeSet does not implement the NavigableSet interface
c. TreeSet stores elements in ascending order by default
d. TreeSet is slower than HashSet for access and retrieval operations

Answer :- For Answers Click Here 

7. What is the primary function of Byte Stream classes in Java?

a. To read and write characters from and to a stream
b. To handle input and output operations with bytes, not characters
c. To manage networking operations for byte-level data
d. To provide a graphical interface for stream operations

Answer :- 

8. Which Writer stream class in Java is typically used to format and write primitive data types and objects as text output?

a. OutputStreamWriter
b. PrintWriter
c. FileWriter
d. DataOutputStream

Answer :- 

9. Which of the following java.io classes allows both reading from and writing to a file at any specific location?

a. File
b. FileInputStream
c. FileOutputStream
d. RandomAccessFile

Answer :- 

10. Which of the following is true about graphical input and output in Java?

a. Java uses ByteStream for handling graphical input and output
b. The java.awt and javax.swing packages are used for graphical input and output
c. Graphical input and output in Java are handled using the Scanner class
d. The System.out class is used for graphical output in Java

Answer :- For Answers Click Here 
Share This Article
Leave a comment