NPTEL Data Structure And Algorithms Using Java Solutions 2023
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 1 Nptel Data Structure And Algorithms Using Java](https://gecmunger.in/wp-content/uploads/2023/07/Nptel-Data-Structure-And-Algorithms-Using-Java-1024x576.png)
NPTEL Data Structure And Algorithms Using Java Week 10 Assignment Answers 2023
1. The class_______allows us to handle a file randomly in contrast to sequentially in InputStream or OutputStream classes. It allows to move file pointer randomly. Moreover, it allows read or write or read-write simultaneously.
a. JAVA IO
b. Fie
c. RandomAccessFile
d. Appending
Answer :- c
2.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 2 a10q2](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a10q2.png)
Answer :- c
3.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 3 a10q3n](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a10q3n.png)
[ihc-hide-content ihc_mb_type=”show” ihc_mb_who=”1,2,3″ ihc_mb_template=”1″ ]
Answer :- d
4. Linear searching with linked list in the best case will have an asymptotic complexity?
a. O(logn
b. O(n)
c. 0(1)
d. O(n/2)
Answer :- c
5. Which of the following statements about interpolation search is correct?
a. Interpolation search works efficiently on sorted arrays.
b. Interpolation search is a type of binary search.
c. Interpolation search always outperforms linear search.
d. Interpolation search uses a fixed mid-point for dividing the search space.
Answer :- a
6. Which of the following is FALSE in case of Hashing?
a. Hashing is a mapping from the Key to its index(location).
b. Division Method
H(k) = k (mod h) if indices start from 0
H(k) = k (mod h)+1 if indices start from 1
c. Collision resolution techniques are Closed hashing and Open hashing
d. linear probing and chaining are not collision resolution techniques
Answer :- d
7. Which of the following is not a condition for Closed Hashing to stop from searching?
a. The key value is found.
b. An unoccupied (or empty) location is encountered.
c. It reaches the location where the search was started.
d. The hash table is resized.
Answer :- d
8.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 4 a10q8](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a10q8.png)
Answer :- d
9.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 5 a10q9](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a10q9.png)
Answer :- c
10.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 6 a10q10](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a10q10.png)
Answer :- b
[/ihc-hide-content]
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 9 Assignment Answers 2023
1. Which of the following statements is/ are INCORRECT when it comes to set collection?
a. Set Interface in Java is present in java.util package.
b. Set Interface extends the Collection interface.
C. Set represents an unordered set of elements which doesn’t allow us to store the duplicate items.
d. We can’t store null element in Set.
Answer :- d
2. Which of the following declarations is/are Incorrect?
a. Set s1 = new HashSetO:
b. Set s2 = new LinkedHashSetO:
c. Set s3 = new TreeSetO;
d. Set s4 = HashSetO:
Answer :- d
3. Which of the following statements is/are incorrect in the case of HashSet class?
a. HashSet extends AbstractSet and implements the set interface.
b. It creates a collection that uses a hash table for storage.
c. HashSet is a generic class that has this declaration:
class HashSet
d. HashSet guarantees the order of its elements because the process of hashing doesn’t usually lend itself to the creation of sorted sets.
Answer :- d
4. Which of the following is/are appropriate ways of iterating over a HashSet?
a. Iterate over a HashSet using a simple for-each loop.
b. Iterate over a HashSet using iterator0.
c. Iterate over a HashSet using Java forEach and Lambda expression.
d. Iterate over a HashSet using iterator0 and forEachRemaining0 method
Answer :- a, b, c, d
5. What is the difference between HashSet and LinkedHashSet?
a. HashSet and LinkedHashSet are the same. There is no difference.
b. HashSet does guarantee the order of its elements because the process of hashing usually lends itself to the creation of sorted sets. In contrast, the LinkdeHashSet doesn’t follow the same order of the items as they are added into the set.
c. HashSet does not guarantee the order of its elements because the process of hashing doesn’t usually lend itself to the creation of sorted sets. In contrast, the LinkedHashSet follows the same order of the items as they are added into the set.
d. HashSet and LinkedHashSet are both implementations of the Set interface in Java, and they doesn’t have any key differences in terms of their characteristics and behavior
Answer :- c
6. Which of the following options is/are Incorrect in the case of Streams in JAVA?
a. A Stream is a sequence of data.
b. Java I/O (Input and Output) is used to process the input and produce the output.
c. “Stream” is called Stream because it is continuous flow of data
d. We can’t perform file handling in Java by java.io API.
Answer :- d
7. Character stream classes are used for?
a. Read and write characters and support a number of input-output-related methods.
b. Only to read characters
c. Only to write characters
d. Read and write characters but doesn’t support input-output related methods
Answer :- a
8. Fill in the blank
class is an abstract class. It is the superclass of all classes representing an outpu stream of bytes. An output stream accepts output bytes and sends them to some sink.
a. OutputStream
b. InputStream
c. Abstract
d. Super
Answer :- a
9. Which of the following is not a use of class OutputStream?
a. Writing bytes
b. Closing a stream
c. Cleaning a buffer
d. Reading bytes
Answer :- d
10.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 7 a9q10](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a9q10.png)
Answer :- d
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 8 Assignment Answers 2023
1. In the context of data structures, what is the primary purpose of an adjacency matrix?
a. To store the values associated with vertices in the graph.
b. To efficiently represent and store the relationships between vertices in a graph.
c. To determine the degree of a vertex in the graph.
d. To find the shortest path between two vertices.
Answer :- b
2. When implementing a breadth-first search (BFS) algorithm on a graph, what data structure is typically used to keep track of vertices in the order they are visited?
a. Stack
b. Queue
с. Heap
d. Linked list
Answer :- b
3. In the context of graph traversal, what is the time complexity of determining whether a graph is bipartite using depth-first search (DFS)?
a. O(V)
b. O(V + E)
c. O(V^2)
d. O(E log V)
Answer :- b
4. Consider a weighted, directed graph with V vertices and E edges. Which data structure is most suitable for finding the shortest paths between all pairs of vertices efficiently?
a. Adjacency matrix
b. Priority queue
c. Stack
d. Hash table
Answer :- a
5. Which Java Collection is commonly used to represent a graph as an adjacency list?
a. ArrayList
b. HashSet
c. TreeMap
d. HashMap
Answer :- d
6. What is the time complexity of retrieving a value from a HashMap in Java?
a. O(1)
b. O(log m)
c. O(n)
d. O(n log n)
Answer :- a
7. Which of the following statements about HashMap in Java is correct?
a. HashMap allows duplicate keys but not duplicate values.
b. HashMap allows duplicate values but not duplicate keys.
c. HashMap does not allow duplicate keys or values.
d. HashMap allows both duplicate keys and duplicate values.
Answer :- b
8. What happens if you attempt to retrieve a value from a HashMap using a key that does not exist in the HashMap?
a. It returns null.
b. It throws a NoSuchElementException.
c. It throws a NullPointerException.
d. It returns the default value associated with the value type.
Answer :- a
9. Which of the following statements) is(are) true?
a. If you put an object with the same key value, it will overwrite the previous one.
b. Always use generics and diamond operator to declare a new map.
c. keySet: returns a Set view of the keys contained in the map.
d. entrySetO: returns a Set view of the mappings contained in this map.
Answer :- a, b, c, d
10. Consider an adjacency matris (M) representation for a simple unweighted graph having V vertices. What is the maximum number of non-zero entries possible in M?
a. V*V
b. V*(V+1)
C. (V*(V+1))/2
d. V*(V-1)
Answer :- d
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 7 Assignment Answers 2023
1. What is the time complexity of searching for an element in a balanced Binary Search Tree with ‘n’ nodes?
a. O(1)
b. O(log n)
c. O(n)
d. O(n log n)
Answer :- b
2.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 8 a7q2](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a7q2.png)
Answer :- a
3. What is the worst-case time complexity of deletion in an AVI tree?
a. O(1)
b. O(log n)
c. O(n)
d. O(n log n)
Answer :- b
4. After inserting a new node into an AVI tree, the balance factor of a particular node becomes -2. With just this information, What rotations) should be performed to restore the AVL tree balance?
a. Right Rotation.
b. Left Rotation.
c. Left-Right Rotation.
d. Right-Left Rotation.
Answer :- a
5. Which of the following traversal sequences can be used to construct a binary search tree uniquely?
a. Inorder and preorder
b. Inorder and postorder
c. postorder and preorder
d. Postorder,level-order. postorder
Answer :- a, b
6. What is the main purpose of a heap data structure?
a. To create a balanced binary search tree.
b. To store elements in a sorted order.
c. To implement priority queues and efficiently retrieve the highest (or lowest) priority element.
d. To represent hierarchical data with multiple levels.
Answer :- c
7.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 9 a7q7](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a7q7.png)
Answer :- b, d
8.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 10 a7q8](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a7q8.png)
Answer :- a
9. You are given the following set of integers: {25, 10, 30, 15, 20, 5}. Construct a min-heap by inserting the integers in the given order. What will be the root of the resulting min–heap?
d. 5
b. 10
c. 15
d. 20
Answer :- a
10. What is the time complexity of the bottom-up heapify operation when constructing a heap from an array of ‘n’ elements?
a. O(1)
b. O(log n)
c. O(n)
d. O(n log n).
Answer :- c
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 6 Assignment Answers 2023
1. Which of the following is FALSE in the case of different types of Binary Trees?
a. A binary tree is a full binary tree, if it contains the maximum possible number of nodes in all levels.
b. A binary tree is said to be a complete binary tree, if all its levels, except possibly the last level, have the maximum number of possible nodes. and all the nodes at the last level appear as far left as possible.
c. A binary tree is said to be a skewed binary tree. if all its levels, all nodes contain only one child.
d. A binary tree is said to be a complete binary tree, if all its levels, except possibly the last level, have the maximum number of possible nodes, and the nodes at the last level may appear anywhere it is possible.
Answer :- d
2.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 11 a6q2n](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a6q2n.png)
Answer :- a
3. Choose the Incorrect statement among the given options.
a. In any binary tree, maximum number of nodes on level 1 is 2′, where 1 2 0.
b. Maximum number of nodes possible in a binary tree of height his 2h – 1.
c. Maximum number of nodes possible in a binary tree of height h is 2h + 1.
d. Minimum number of nodes possible in a binary tree of height h is h
Answer :- c
4. What is/are the possible ways of Binary Trees representation?
a. Using only array
b. Using only linked list structure
c. Using either of an Array or Linked list structure
d. Special binary tree data structure is needed: there is no other way
Answer :- c
5. Which of the following is not a major operations on a binary tree?
a. Traversal
b. Insertion
c. Deletion
d. Peek
Answer :- d
6.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 12 a6q6n](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a6q6n.png)
Answer :- d
7. Which of the following statements is/are FALSE in contest of Binary Search Tree?
a. The nodes which have the same parent are called siblings
b. Minimum number of children that is possible for a node is known as the degree of a node.
c. The node which is at the end and which does not have any child is called leaf node.
d. Root is a specially designated node which has no parent
Answer :- b
8.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 13 a6q8new](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a6q8new.png)
Answer :- c
9. Which of the following is False in the case of Binary Search Tree?
a. Inorder traversal on a BST gives the data in ascending order
b. Inorder traversal on a BST gives the data in no particular order
c. the minimum value is at the left-most node
d. the maximum value is at the right-most node
Answer :- b
10. Which of the following is FALSE with respect to complexity of Binary Search Tree?
a. Complexity of Searching in a Binary Search Tree in worst case is O(n)
b. Complexity of Searching in a Binary Search Tree in best case is O(1)
c. Complexity of Searching in a Binary Search Tree in worst case is O(nlog,n)
d Complexity of Searching in a Binary Search Tree in average case id O(log,n)
Answer :- c
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 5 Assignment Answers 2023
1. Which of the following statements about a stack data structure is true?
a. Elements are removed from the front (or head) of the stack.
b. Elements are removed from the rear (or tail) of the stack.
c. The last element added to the stack is the first one to be removed.
d. The first element added to the stack is the first one to be removed.
Answer :- c
2. Which operation in a stack data structure can lead to an “underflow” condition?
a. Push
b. Pop
c. Peek.
d. Clear
Answer :- b
3. Which of the following applications is best suited for utilizing a stack data structure?
а. Implementing a queue for a printing system.
b. Storing the file system structure on a computer.
c. Evaluating arithmetic expressions.
d. Managing a sorted list of items.
Answer :- c
4.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 14 a5q4](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q4.png)
Answer :- b
5.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 15 a5q5](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q5.png)
Answer :- b
6.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 16 a5q6](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q6.png)
Answer :- c
7.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 17 a5q7](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q7.png)
Answer :- b
8.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 18 a5q8](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q8.png)
Answer :- c
9.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 19 a5q9](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q9.png)
Answer :- a
10.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 20 a5q10](https://storage.googleapis.com/swayam-node1-production.appspot.com/assets/img/noc23_cs85/a5q10.png)
Answer :- d
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 4 Assignment Answers 2023
Q1. In the worst case, the number of comparisons needed to search an item stored in a single linked list structure of length 100 is
а. 98
b. 101
c. 99
d. 100
Answer:- d
Q2. What does the following function do given a linked list with the first node as head?
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 21 image 31](https://gecmunger.in/wp-content/uploads/2023/08/image-31.png)
Answer:- b
Q3. Consider the given Java code snippet that implements a singly linked list:
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 22 image 32](https://gecmunger.in/wp-content/uploads/2023/08/image-32-594x1024.png)
Answer:- c
4. Which of the following operations is performed more efficiently by a doubly linked list than by linear linked list?
a. Deletion after a node
b. Insertion after a node
c. Searching
d. Traversal
Answer:- a
5. What is the time complexity of deletion from the end in a circular doubly linked list?
a. O(1)
b. O(n)
c. O(log n)
d. O(log log n)
Answer:- a
6. Which of the following statements) is(are) true about Java LinkedList?
a. Java LinkedList class cannot contain duplicate elements.
b. Java LinkedList class maintains insertion order.
C. Java LinkedList class is non synchronized.
d. Java LinkedList class cannot be used as a list, stack or queue.
Answer:- b, c
7. For which of the following applications, Linkedlist may not be the good choice?
a. Sparse matrix manipulation
b. Random Access Requirements
C. Polynomial manipulation
d. memory management
Answer:- b
8. Which of the following statements is true about arrays and linked lists in Java?
a. Arrays are always faster than linked lists.
b. Linked lists are always faster than arrays.
c. Arrays are better for random access, while linked lists are better for sequential access.
d. Arrays and linked lists have the same performance for both random and sequential access.
Answer:- c
9. Suppose you have a linked list of integers and you want to delete the first node in the list. Which of
the following statements is true?
a. The time complexity of the deletion operation is O(1).
b. The time complexity of the deletion operation is O(n).
c. The time complexity of the deletion operation depends on the size of the integer to be deleted.
d. The time complexity of the deletion operation depends on the location of the deletion point.
Answer:- a
10. Which of the following is not a valid declaration of a collection of type List?
a. LinkedList<String> a = new LinkedList<string>();
b. LinkedList<String> b = new LinkedList <>();
c. LinkedList<int> c = new LinkedList<string>();
c = new LinkedList<Integer> d = new LinkedList<>(1, 2, 3, 4, 5);
Answer:- c
NPTEL Data Structure And Algorithms Using Java Week 3 Assignment Answers 2023
1. Which data structure is the collection of finite, ordered, and homogeneous data elements?
a. Array
b. Graph
c. Мар
d. Trees
Answer:- a
2. Consider the following piece of code.
public class Main {
public static void main(String args[]) {
char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
for (int i = 0; i < a.length; i = i + 2)
System.out.print(" " + a[i]);
}
}
Which of the following is an output of the above program?
a. abodef
b. ace
c. bdf
d. abdf
Answer :- b
3. Consider the following program.
public class Main {
public static void main(String args[]) {
int[] a = new int[0];
a[0] = 12;
System.out.println(a);
}
}
Which of the following is an output of the above program?
a. 12
b. Exception
c. O
d. Null
Answer :- b
4. Consider the program given below.
public class Main {
public static void main (String args[]) {
int [] a = new int [201;
System.out.printin (a[10]);
}
}
Which of the following is an output of the above program?
a. 0
b. Compile time error
c. Runtime error
d. Garbage vale
Answer:- a
5. Which of the following statements is true regarding ArrayList in Java?
a. ArrayList is a synchronized data structure, making it thread-safe.
b. ArrayList allows duplicate elements and maintains insertion order.
c. ArrayList is a resizable array that automatically increases its size when elements are added.
d. ArrayList can only store primitive data types like int, double, and char.
Answer :- b
6. Which of the following classes implement a dynamic array?
a. ArrayList
b. LinkedList
c. DynamicList
d. AbstractList
Answer :- a
7. Which method is used to remove all elements from an ArrayList?
a. removeAllO
b. clear
c. deleteAllO
d. eraseA110
Answer :- b
8. What will be the output of the following Java code?
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 23 image 15](https://gecmunger.in/wp-content/uploads/2023/08/image-15.png)
Which of the following is an output of the above program?
а. “Apple”
b. “Banana”
c. “Orange”
d. IndexOutOfBoundsException will be thrown.
Answer :- c
9. What is the time complexity of adding an element at the end of an ArrayList?
a. O(1)
b. O(log n)
c. O(n)
d. O(n log n)
Answer :- a
10. Which of the following methods is used to find the index of the first occurrence of a specific element in an ArravList?
a. findIndex
b. indexOf0
c. search
d. findFirstO
Answer :- b
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 2 Assignment Answers 2023
1. Which of the following is/are FALSE in the case of Data Structure in Java?
a. Array is an indexed linear data structure
b. linked list is a sequential non- linear data structure
C. stack and queue are Linear data structure
d. set, tree, table, and graph are Non-linear data structure
Answer :- b. linked list is a sequential non- linear data structure
2. 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
3. Which among the following is a Java Collection Framework(JCF) Class?
a. Set
b. List
c. Queue
d. Vector
Answer :- d. Vector
4. Choose the right option to complete the following sentence in the case of EnumSet EnumSet extends AbstractSet and implements
a. Enum type
b. Enum
c. AbstractSet
d. Set
Answer :- d. Set
5. Which of the following statement is incorrect with respect to ‘Map’ in Java?
a. A Map is an obiect that maps keys to values
b. Map is a collection of key-value pairs.
c. Map is a generic interface that has the declaration: interface Map <I>
d. SortedMap interface doesn’t extend Map.
Answer :- d. SortedMap interface doesn't extend Map.
6. 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.
7. In Java Collection Framework(JCF) Dictionary is ___________?
a. A concrete implementation
b. An interface
c. An abstract class
d. A data structure for storing only integers
Answer :-c. An abstract class
8. Which of the following interface(s) is (are) NOT descendant(s) of java.util.Collection?
a. java.util. SortedMap
b. java.util.Set
c. java.util. SortedSet
d. java.util. Queue
Answer :- a. java.util. SortedMap
9. Which of the following declaration(s) is(are) not correct to instantiate a collection object?
a. List <data-type list1 = new ArrayList():
b. List <data-type list2 = new LinkedList();
c. List <data-type list3 = new Vector():
d. List <data-type list4 = new PriorityQueue() :
Answer :- d. List <data-type list4 = new PriorityQueue :
10. Which of these interface handle sequences?
a. Set
b. Array
c. List
d. Collection
Answer :- c. List
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
NPTEL Data Structure And Algorithms Using Java Week 1 Assignment Answers 2023
1. What is “generic programming” in Java?
a. A programming paradigm that focuses on reusability and type safety.
b. A technique to optimize code execution in Java programs.
c. A feature to dynamically modify variable types at runtime.
d. A method to generate random data in Java programs.
Answer :- a. A programming paradigm that focuses on reusability and type safety. "Generic programming" in Java refers to the use of generics, a programming feature introduced in Java 5 (J2SE 5.0). Generics allow classes, interfaces, and methods to be parameterized with types. By using generics, you can create classes and methods that can work with different types while ensuring type safety. This helps to improve code reusability and maintainability by writing more generic and flexible components.
2. Which symbol is used to denote a generic type in Java?
a. *
b. &
c. #
d. <>
Answer :- d. <> The symbol used to denote a generic type in Java is <>. It is referred to as the diamond operator or angle brackets. Generics in Java allow you to create classes, interfaces, and methods that can work with different types while providing type safety. The diamond operator is used when defining a generic class or when instantiating an object of a generic class to specify the type parameter.
3. Consider the following piece of code.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 24 image 8](https://gecmunger.in/wp-content/uploads/2023/07/image-8.png)
Which of the following is true?
a. The code suffers from syntax errors.
b. Program will give a compile-time error.
c. It will produce output: 5 4 3 2 1
d. Program will yield a run-time error.
Answer :- c. It will produce output: 5 4 3 2 1 The code is correct syntactically and will execute without any compilation errors or runtime errors. It starts the loop with i initialized to 5, and then decrements i in each iteration until it becomes 0 (excluding 0). Therefore, it will print the numbers 5, 4, 3, 2, and 1, each on a separate line.
4. What will be the output of the following code snippet?
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 25 image 9](https://gecmunger.in/wp-content/uploads/2023/07/image-9.png)
a. Compile-time eifor
b. 9 5 47
c. Run-time error
d. 9 5 4 7
Answer :- d. 9 5 4 7
5.Which of these is wildcard symbol?
a. ?
b. !
C. &
d. %
Answer :- a. Compile-time eifor The option "Compile-time eifor" suggests that there is a typo in the code, and there may be a misspelling of the for keyword. If the code snippet contains "eifor" instead of "for," it will result in a compilation error.
6. Which of the following keywords is used to declare an upper bounded wildcard?
a. bound
b. extends
c. implement
d. super
Answer :- b. extends In Java, the keyword "extends" is used to declare an upper bounded wildcard when working with generics. An upper bounded wildcard restricts the type that can be used as a parameter to a specific class or its subclasses.
7. Can primitive types be used as type arguments in Java generics?
a. Yes, any primitive type can be used.
b. No. only reference types are allowed as type arguments.
c. Yes, but they need to be wrapped in their corresponding wrapper classes.
d. No, primitive types are not compatible with Java generics.
Answer :- c. Yes, but they need to be wrapped in their corresponding wrapper classes.
8. What is type erasure in Java generics?
a. The process of automatically converting generic types to their raw types during compilation.
b. The ability to perform runtime type checking of generic types.
c. The process of inferring type arguments based on method calls.
d. The feature that allows dynamic dispatch of the generic method.
Answer :- a. The process of automatically converting generic types to their raw types during compilation. Type erasure in Java generics is the process by which the compiler removes or "erases" the type parameters used in generic code during compilation. This means that the generic type information is not retained at runtime. Instead, the generic types are replaced with their raw types (non-generic types), which are used for compatibility with pre-generic Java code.
9. Which of the following statements) is(are) true with respect to the use of generics?
a. The Java compiler enforces tighter type checks on generic code at compile time.
b. Generics support programming types as parameters.
c. Generics enable you to implement generic algorithms.
d. In case of a generic method, the same code can work for different types of data.
Answer :- a. The Java compiler enforces tighter type checks on generic code at compile time. b. Generics support programming types as parameters. c. Generics enable you to implement generic algorithms. d. In the case of a generic method, the same code can work for different types of data.
10.
![[Week 10] NPTEL Data Structure And Algorithms Using Java Assignment Answers 2023 26 image 10](https://gecmunger.in/wp-content/uploads/2023/07/image-10.png)
Which of the following statements about the code snippet is correct?
a. The code will compile and execute without any error.
b. code will compile but throw a runtime exception.
c. The code will not compile due to a type mismatch error
d. The code will not compile due to a missing implementation error.
Answer :- c. The code will not compile due to a type mismatch error
Course Name | Data Structure And Algorithms Using Java |
Category | NPTEL Assignment Answer |
Home | Click Here |
Join Us on Telegram | Click Here |
Pingback: NPTEL Data Structure And Algorithms Using Java Week 9 Assignment Answers 2023 - DBC Itanagar