COSC-2336 Collections - Programming Fundamentals III Final Exam Correct Questions and Answers 100% A+ Graded
COSC-2336 Collections - Programming Fundamentals III Final Exam Correct Questions and Answers 100% A+ Graded A list in which each stored element is associated with a reference to its successor is called - CORRECT ANSWER-a linked list To allocate storage for its elements, an array-based list such as ArrayList uses - CORRECT ANSWER-contiguous allocation To allocate storage for their elements, linked lists use - CORRECT ANSWER-linked allocation A linked list is represented by a reference to - CORRECT ANSWER-the first node in the list, unless the list is empty, in which case the reference is set to null A Node class for a linked list that can hold elements of type Object can be declared to have fields - CORRECT ANSWER-Object element; Node next; In a linked list, the predecessor of a node X - CORRECT ANSWER-is undefined if X is the first node, otherwise it is the node whose index is one less than the index of X The objects that form the units of memory allocation in a linked lists are called - CORRECT ANSWER-nodes To remove the first node in a nonempty linked list, - CORRECT ANSWER-move the head reference one node forward: head = ; A systematic procedure for starting at the first node in a list, and visiting all nodes in the list by going from each node to its successor is called - CORRECT ANSWER-a traversal In a linked list implementation using a reference first to point to the first node of the list, a method isEmpty() can test to see if the list is empty by executing the statement(s) - CORRECT ANSWER-return first == null; A list method void add(int index, E x) seeking to add an element x that is an object of a class E to a list, should throw an IndexOutOfBoundsException when - CORRECT ANSWER-the index is negative, or greater than the size of the list A method int size( ) in a linked list class returns the number of elements stored in the list by executing the single statement return count; For this to work correctly, - CORRECT ANSWER-It is not possible for size to just return the count value: the size method must set count to 0 and then increment count once for each element in the list. A linked list class keeps its elements in the order in which they are added, with the index of an element X being greater than the index of any element added to the list before X. Addition of new elements to such a list can be made more efficient - CORRECT ANSWER-none of the above A list method E remove(int index) designed to remove and return the element at the given index should throw IndexOutOfBoundsException when - CORRECT ANSWER-the index is negative, or is greater than, or equal to, the size of the list A doubly linked list makes it easy to - CORRECT ANSWER-move from any node to its successor, and from any node to its predecessor A circularly linked list makes it easy to - CORRECT ANSWER-jump from the last node to the first In a typical circular doubly linked list, a node has - CORRECT ANSWER-a field to store the element, and two references to keep track of successor and predecessor nodes A list can be considered a recursive data structure because - CORRECT ANSWER-if you remove the head of the list, what remains is also a list The tail of a list - CORRECT ANSWER-is what you get when take a list and remove its head When using recursion on linked lists - CORRECT ANSWER-the recursive method should be made private, and should be called by a public non-recursive method A Java collection - CORRECT ANSWER-is an object that is is used as a container for other objects The three major categories of Java collections are - CORRECT ANSWER-lists, sets, and maps A collection that stores its elements in an (ordered) sequence, and allows access to each element by its position in the sequence is called a - CORRECT ANSWER-list A collection that does not impose a positional order on its elements, and does not allow duplicates is called a - CORRECT ANSWER-set A collection whose elements are pairs of keys and values is called - CORRECT ANSWER-a map Which of the following is true? - CORRECT ANSWER-A map allows duplicate keys to be stored; WRONG ANSWER Which of the following is true? - CORRECT ANSWER-Both the Set and List interfaces extend the Collection interface The concrete classes that implement the List interface are - CORRECT ANSWER-None of the above; WRONG ANSWER If you try to add an item to an ArrayList whose size is equal to its capacity, - CORRECT ANSWER-a new ArrayList object with twice the capacity is created, and the elements are moved to this new ArrayList. An object that is used to retrieve objects from a collection is called - CORRECT ANSWER-an accessor; WRONG ANSWER Which of the following is true? - CORRECT ANSWER-Any iterator can move forward as well as backwards through a collection; WRONG ANSWER Which of the following is true? - CORRECT ANSWER-The ListIterator interface is a subinterface of the Iterator interface The Vector class - CORRECT ANSWER-works just like ArrayList, except it is synchronized A LinkedList is the right kind of list to use when - CORRECT ANSWER-there are lots of insertions and deletions in the middle of the list A collection that is synchronized - CORRECT ANSWER-protects data from corruption when the data is accessed by multiple threads A collision occurs when - CORRECT ANSWER-objects whose values are not equal have the same hash code When using a HashSet - CORRECT ANSWER-you should override the hashCode and equals methods defined in the Object class Which of the following is true of a HashSet object? - CORRECT ANSWER-The time required to add an element, or search for an element, increases as the number of collisions increases LinkedHashSet differs from HashSet because - CORRECT ANSWER-the LinkedHashSet allows elements to be retrieved in the same order as they were added Comparable - CORRECT ANSWER-is a class that allows two objects to be compared; WRONG ANSWER Comparable - CORRECT ANSWER-specifies a single method, compareTo Comparator - CORRECT ANSWER-specifies two methods, compare and equals A TreeSet - CORRECT ANSWER-is like a Set that allows elements to be retrieved according to their natural order, or according to an order specified by a Comparator A HashMap - CORRECT ANSWER-is a subclass of Map that implements the HashCode interface;WRONG ANSWER
Written for
- Institution
- COSC 2336
- Course
- COSC 2336
Document information
- Uploaded on
- May 28, 2024
- Number of pages
- 28
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
cosc 2336 collections programming fundamentals i