1.
The constructor in the SeparateIterator class
Correct Answer
C. Both a & b
Explanation
The constructor in the SeparateIterator class initializes the iterator so it begins at the first entry in the list and connects the iterator to the list in question. This means that when the SeparateIterator object is created, it is set to point to the first entry in the list and is ready to iterate through the elements of the list. Therefore, the correct answer is both a & b.
2.
A separate class iterator is a good choice when
Correct Answer
A. An ADT’s implementation does not have an iterator and cannot be altered
Explanation
When an ADT's implementation does not have an iterator and cannot be altered, a separate class iterator is a good choice. This allows for the creation of a new class specifically designed to iterate over the ADT's elements without modifying its implementation. This approach ensures that the original ADT remains unchanged while still providing the functionality of iteration.
3.
In the IteratorForLinkedList class, the hasNext method determines iteration has ended by
Correct Answer
B. Check if the nextNode variable is null
Explanation
The correct answer is to check if the nextNode variable is null. This is because in a linked list, each node has a reference to the next node in the list. So, if the nextNode variable is null, it means that there are no more nodes left to iterate over, indicating that the iteration has ended.
4.
What does the hasNext method return when the list is empty?
Correct Answer
A. False
Explanation
The hasNext method returns false when the list is empty because there are no elements in the list to iterate over.
5.
In the ListIteratorForArrayList class, the remove method throws an IllegalStateExeption when
Correct Answer
D. All of the above
Explanation
The remove method in the ListIteratorForArrayList class throws an IllegalStateException when any of the following conditions are met: the next method was not called just before it, the previous method was not called just before it, or remove has been called since the last call to next or previous. This means that if any of these conditions are true, calling the remove method will result in an IllegalStateException being thrown. Therefore, the correct answer is "all of the above".
6.
Writing “? super T” where T defines a generic type means
Correct Answer
A. Any super class of T
Explanation
Writing "? super T" where T defines a generic type means that the type parameter T can be replaced with any super class of T. This allows for flexibility in the type hierarchy, as any super class of T can be used in place of T. This is useful when defining generic methods or classes that need to accept a wide range of types.
7.
To prevent a subclass from overriding protected methods, we declare them to be
Correct Answer
B. Final
Explanation
Final keyword is used in Java to prevent a method from being overridden in a subclass. When a method is declared as final, it cannot be modified or overridden by any subclass. In the given question, the correct answer is "final" because it is the keyword that prevents a subclass from overriding protected methods. Protected methods can still be accessed by subclasses, but if they are declared as final, they cannot be overridden.
8.
Which method is declared to be protected in the LinkedChainBase class?
Correct Answer
D. All of the above
Explanation
The correct answer is "all of the above" because all three methods - addFirstNode, addAfterNode, and removeAfterNode - are declared as protected in the LinkedChainBase class. Being declared as protected means that these methods can only be accessed within the class itself and its subclasses, providing encapsulation and allowing for controlled access to these methods.
9.
Assume you have an array of unsorted items that allows duplicate entries and that the item you aresearching for is present. Using an iterative sequential search on an unsorted array, the loop exits when
Correct Answer
A. It locates the first entry in the array that matches the item being searched for
Explanation
In an iterative sequential search on an unsorted array, the loop exits when it locates the first entry in the array that matches the item being searched for. This means that as soon as a match is found, the loop stops and the search is considered successful. The search does not continue to find any other matching entries in the array.
10.
Given the following array, how many comparisons to an array entry are performed to search for the number13 if you use the binary search algorithm?
Correct Answer
A. 1
Explanation
In binary search, the algorithm compares the target value with the middle element of the array. If the target value is smaller, it continues the search on the left half of the array; if it is larger, it continues on the right half. In this case, the target value is 13. The algorithm compares it with the middle element, which is 6. Since 13 is greater than 6, the algorithm continues the search on the right half. There is only one comparison made in this process, which is comparing 13 with 6. Therefore, the answer is 1.
11.
Classes that implement the Comparable interface must define
Correct Answer
C. CompareTo
Explanation
Classes that implement the Comparable interface must define the compareTo method. This method is used to compare objects of the class and determine their order. It returns a negative integer if the current object is less than the object being compared, zero if they are equal, and a positive integer if the current object is greater. The other methods mentioned (equals, lessThan, notEquals) are not required by the Comparable interface and may or may not be implemented depending on the specific needs of the class.
12.
Given a table size of 19 the hash function h(k) = k % table size, what index does the entry 24 map to?
Correct Answer
A. 5
Explanation
The given hash function uses the modulo operator to calculate the index. In this case, the entry 24 will be divided by the table size (19) and the remainder will be taken. The remainder of 24 divided by 19 is 5. Therefore, the entry 24 maps to index 5 in the table.
13.
If you use quadratic probing for collision resolution, it is recommended that the hash table be
Correct Answer
A. Less than half full
Explanation
When using quadratic probing for collision resolution in a hash table, it is recommended to keep the hash table less than half full. This is because quadratic probing can lead to clustering, where consecutive collisions occur in close proximity to each other. If the table is too full, the likelihood of clustering increases, which can negatively impact the performance of the hash table. By keeping the table less than half full, it allows for a better distribution of the elements and reduces the chances of clustering.
14.
Hashing is a good technique for implementing a dictionary when _____ is the primary task.
Correct Answer
B. Searching
Explanation
Hashing is a good technique for implementing a dictionary when searching is the primary task because it allows for efficient retrieval of data. Hashing involves using a hash function to map keys to indexes in an array, making it easy to locate the desired value by directly accessing the corresponding index. This results in constant time complexity for searching, making it an ideal choice for scenarios where quick retrieval of data is required.
15.
Nodes that are children of the same parent node are called _____.
Correct Answer
D. Siblings
Explanation
Nodes that are children of the same parent node are called siblings. Siblings share the same parent node and are at the same level in the tree structure. They are connected through their common parent and do not have any direct hierarchical relationship with each other. Therefore, the correct answer is siblings.
16.
A node with no children is called a(n) _____.
Correct Answer
A. Leaf
Explanation
A node with no children is called a leaf because it is the end point of a tree branch. It does not have any child nodes branching off from it, hence it is referred to as a leaf node.
17.
A tree in which each node may have at most two children is called a(n) _____ tree.
Correct Answer
B. Binary
Explanation
A tree in which each node may have at most two children is called a binary tree. In a binary tree, each node can have either zero, one, or two children. This type of tree is commonly used in computer science and data structures. The term "binary" refers to the fact that each node has two possible children.
18.
A node in a binary tree is an object that references a data object and
Correct Answer
A. Two child nodes in a tree
Explanation
A node in a binary tree is an object that references a data object and two child nodes in a tree. In a binary tree, each node can have at most two child nodes, commonly referred to as the left child and the right child. These child nodes can also be considered as separate nodes in the tree. Therefore, the correct answer is that a node in a binary tree references two child nodes in a tree.
19.
In a binary tree, if both the left and right child of a node are null
Correct Answer
C. The node is a leaf
Explanation
If both the left and right child of a node in a binary tree are null, it means that the node does not have any further child nodes. This indicates that the node is a leaf node, which is a node that does not have any children. Therefore, the correct answer is that the node is a leaf.