Exam3 REVIEW CSCI1302
Exam3 REVIEW CSCI1302
a) Queue interface.
b) Set interface.
c) List interface.
d) Stack interface.
2) A list is a collection that ____.
a) should be used when you need to remember the order of elements in the collection.
b) allows items to be added at one end and removed at the other end.
c) does not allow elements to be inserted in any position.
d) manages associations between keys and values.
3) A stack is a collection that ____.
a) remembers the order of elements, and allows elements to be added and removed only at one end.
b) does not remember the order of elements but allows elements to be added in any position.
c) remembers the order of elements and allows elements to be inserted in any position.
d) remembers the order of elements and allows elements to be inserted only at one end and removed only at the
other end.
4) A queue is a collection that ____.
a) remembers the order of elements, and allows elements to be added and removed only at one end.
b) does not remember the order of elements but allows elements to be added in any position.
c) remembers the order of elements and allows elements to be inserted in any position.
d) remembers the order of elements and allows elements to be inserted only at one end and removed only at the
other end.
5) A collection without an intrinsic order is called a ____.
a) list
b) stack
c) set
d) queue
6) A collection that allows items to be added only at one end and removed only at the other end is called a ____.
a) list
b) stack
c) set
d) queue
7) A collection that remembers the order of items, and allows items to be added and removed only at one end is
called a ____.
a) list
b) stack
c) set
d) queue
8) A collection that allows speedy insertion and removal of already-located elements in the middle of it is called
a ____.
a) linked list
b) stack
c) set
d) queue
9) Which data structure would best be used for keeping track of a growing set of groceries to be purchased at
the food market?
a) queue
b) stack
c) list
d) array
10) What is included in a linked list node?
I a reference to its neighboring nodes
II an array reference
III a data element
a) I
b) II
c) II and III
d) I and III
11) Which of the following statements about linked lists is correct?
a) Once you have located the correct position, adding elements in the middle of a linked list is inefficient.
b) Visiting the elements of a linked list in random order is efficient.
c) When a node is removed, all nodes after the removed node must be moved down.
d) Linked lists should be used when you know the correct position and need to insert and remove elements
efficiently.
12) We might choose to use a linked list over an array list when we will not require frequent ____.
I random access
II inserting new elements
III removing of elements
a) I
b) II
c) III
d) II and III
13) Which nodes need to be updated when we insert a new node to become the fourth node from the beginning
of a doubly-linked list?
a) The current third node.
b) The current third and fourth nodes.
c) The current first node.
b) myList.removeLast();
c) myList.getLast();
d) myList.pop();
26) A(n) ____ is a data structure used for collecting a sequence of objects that allows efficient addition and
removal of already-located elements in the middle of the sequence.
a) stack
b) queue
c) linked list
d) priority queue
27) What is the meaning of the type parameter E, in the LinkedList<E> code fragment?
a) The elements of the linked list are of class E.
b) The elements of the linked list are of any subclass of class E.
c) The elements of the linked list are any type supplied to the constructor.
d) The elements of the linked list are of class Object.
28) Which method is NOT part of the ListIterator interface?
a) delete
b) add
c) next
d) previous
29) Consider the code snippet shown below. Assume that employeeNames is an instance of type
LinkedList<String>.
for (String name : employeeNames)
{
// Do something with name here
}
a) array
b) singly
c) doubly
d) randomly
39) Assume you are using a doubly-linked list data structure with many nodes. What is the minimum number of
node references that are required to be modified to remove a node from the middle of the list? Consider the
neighboring nodes.
a) 1
b) 2
c) 3
d) 4
40) In a linked list data structure, when does the reference to the first node need to be updated?
I inserting into an empty list
II deleting from a list with one node
III deleting an inner node
a) I
b) II
c) I and II
d) III
41) Consider the following code snippet:
LinkedList<String> myLList = new LinkedList<String>();
myLList.add("Mary");
myLList.add("John");
myLList.add("Sue");
ListIterator<String> iterator = myLList.listIterator();
iterator.next();
iterator.next();
iterator.add("Robert");
iterator.previous();
iterator.previous();
iterator.remove();
System.out.println(myLList);
50) Assume that you have declared a set named mySet to hold String elements. Which of the following
statements will correctly remove an element from mySet?
a) mySet.get("apple");
b) mySet.remove("apple");
c) mySet.pop("apple");
d) mySet.delete("apple");
51) When the buffer for an array list must be grown, a single reallocation operation takes ____ time.
a) O(n)
b) O(1)
c) O(log(n))
d) O(n2)
52) When considering the reallocation operation for a list whose buffer is full, on average it will take ____ time.
a) O(n)
b) O(1)
c) O(1)+
d) O(n2)
53) Which of the following statements about array list and doubly-linked list operations is correct?
a) It is more efficient to add an element in the middle of an array list than a doubly-linked list.
b) It is more efficient to add an element to the beginning of an array list than a doubly-linked list.
c) It is more efficient to remove an element in the middle of an array list than a doubly-linked list.
d) It is more efficient to retrieve an element in the middle of an array list than a doubly-linked list.
54) Array list operations that were studied included adding/removing an element at the end or in the middle, and
retrieving the kth element. Which of the following statements about these array list operations is correct?
a) The most expensive operation of an array list is to add an element at the end.
b) The most expensive operation of an array list is to remove an element at the end.
c) The most expensive operation of an array list is to add an element in the middle.
d) The most expensive operation of an array list is to retrieve an arbitrary element.
55) Array list operations that were studied included adding/removing an element at the end or in the middle, and
retrieving the kth element. Which of the following statements about these array list operations is correct?
a) The least expensive operation of an array list is to add an element at the end.
b) The least expensive operation of an array list is to remove an element at the end.
c) The least expensive operation of an array list is to add an element in the middle.
d) The least expensive operation of an array list is to retrieve an arbitrary element.
56) Linked list operations that were studied included adding/removing an element at the end or in the middle,
and retrieving the kth element. If the iterator is currently pointing to the correct location for insertion or
removal, which of the following statements about these doubly-linked list operations is correct?
a) The most expensive operation of a doubly-linked list is to add an element at the end.
b) The most expensive operation of a doubly-linked list is to remove an element at the end.
c) The most expensive operation of a doubly-linked list is to add an element in the middle.
d) The most expensive operation of a doubly-linked list is to retrieve an arbitrary element.
57) Linked list operations that were studied included adding/removing an element at the end or in the middle,
and retrieving the kth element. If the iterator is currently pointing to the correct location for insertion or
removal, which of the following statements about these doubly-linked list operations is correct?
a) The least expensive operation of a doubly-linked list is to add an element at the end.
b) The least expensive operation of a doubly-linked list is to retrieve an arbitrary element.
c) The least expensive operation of a doubly-linked list is to add an element in the middle.
d) All of these operations have the same time cost.
58) Which operations from the array list data structure could be used in the implementation of the push and pop
operations of a stack data structure?
I addLast
II addFirst
III removeFirst
a) I
b) II
c) I and II
d) II and III
59) Which of the following operations from the array list data structure could be used in the implementation of
the push and pop operations of a stack data structure?
I addLast
II addFirst
III removeLast
a) I
b) II
c) I and III
d) II and III
60) Complete the following code, which is intended to add an element to the top of a stack implemented as a
linked list.
Node newNode = new Node();
newNode.data = element;
_________________
_________________
a)
first = newNode;
newNode.next = first;
b)
newNode.next = first;
first = newNode;
c)
newNode.previous = first;
first.next = newNode;
d)
first = newNode;
newNode.previous = first;
61) A stack can be implemented as a sequence of nodes in a linked list or an array list. Which of the following
statements about this is correct?
a) If implementing the stack as a linked list, the least expensive approach is to add and remove elements at the
end.
b) If implementing the stack as an array list, the least expensive approach is to add and remove elements at the
end.
c) If implementing the stack as an array list, there is no cost difference whether adding and removing elements
at the beginning or the end.
d) If implementing the stack as a linked list, there is no cost difference whether adding and removing elements
at the beginning or the end.
62) A stack can be implemented as a sequence of nodes in a linked list or an array list. Which of the following
statements about this is correct?
a) If implementing the stack as a linked list, it is more expensive to add and remove elements at the end than at
the beginning.
b) If implementing the stack as an array list, it is more expensive to add and remove elements at the end than at
the beginning.
c) If implementing the stack as an array list, there is no cost difference whether adding and removing elements
at the beginning or the end.
d) If implementing the stack as a linked list, there is no cost difference whether adding and removing elements
at the beginning or the end.
63) When implementing a queue as a singly-linked list, which of these statements is correct?
a) For better efficiency, nodes should be added at the back and removed at the front.
b) For better efficiency, nodes should be added at the front and removed at the back.
c) There is no difference in efficiency whether nodes are added at the front and removed at the back, or added at
the back and removed at the front.
d) You cannot effectively implement a queue as a singly-linked list.
64) You have implemented a queue as a singly-linked list, adding elements at the end and removing elements at
the front. What is the cost of the add operation?
a) O(log n)
b) O(n)
c) O(n2)
d) O(1)
65) You have implemented a queue as a singly-linked list, adding elements at the end and removing elements at
the front. What is the cost of the remove operation?
a) O(log(n))
b) O(n)
c) O(n2)
d) O(1)
66) Elements in a hash table are said to ____ when they have the same hash code value.
a) be equivalent
b) compress
c) collide
d) buffer well
67) A hash function is considered good if it ____.
a) does not require compression.
b) detects duplicate elements.
c) results in low integer values.
d) minimizes collisions.
68) Which of the following statements about hash tables is correct?
a) The hash code is used to determine where to store each element.
b) Elements in the hash table are sorted in hash code order.
c) A hash table allows duplicate elements.
d) No two elements of a hash table can have the same hash code.
69) Which of the following statements about hash tables is NOT correct?
a) Each entry in a hash table points to a sequence of nodes whose elements have the same compressed hash
code.
b) Elements with the same hash code are stored as nodes in a bucket associated with that hash code.
c) A compressed hash code is used as an array index into the hash table.
d) All elements of a hash table must be searched sequentially to determine if an element already exists.
70) Assume that you have a hash table in which there are few or no collisions. What is the time required to
locate an element in this hash table?
a) O(log n)
b) O(n)
c) O(n2)
d) O(1)
71) In the separate chaining technique for handling collisions in a hash table, ____.
a) colliding elements are stored in a nested hash table.
b) colliding elements are placed in empty locations in the hash table.
c) colliding elements are stored in linked lists associated with the hash code.
d) the hash code is compressed to obtain unique hash codes.
72) In the open addressing technique for handling collisions in a hash table, ____.
a) colliding elements are stored in a nested hash table.
b) colliding elements are placed in empty locations in the hash table.
c) colliding elements are stored in linked lists associated with the hash code.
d) the hash code is compressed to obtain unique hash codes.
73) Complete the following code snippet, which is intended to compress a hash code to become a valid array
index:
int h = x.hashCode();
if (h < 0) { h = -h; }
_______________
a) position
b) position
c) position
d) position
=
=
=
=
arrayLength % h;
arrayLength / h;
h / arrayLength;
h % arrayLength;
74) Complete the following code snippet, which is intended to compress a hash code to become a valid array
index:
_____________________
if (h < 0) { h = -h; }
position = h % arrayLength;
a) double h = x.hashCode();
b) double h = x.getHashCode();
c) int h = x.hashCode();
d) int h = x.getHashCode();
75) Why is it not typical to use the hashCode method result directly as an index for array storage?
I because the hashcode method returns a double
II the values are potentially very large
III the values are not type int
a) I
b) I and II
c) I and III
d) II
76) Consider the following code snippet, which computes h, the array index for storing x in a hash table.
int h = x.hashCode();
if (h < 0) { h = -h; }
h = h % size;
d) sharing
78) Assume that you have a hash table in which there are few or no collisions. What is the time required to add
a new element to this hash table?
a) O(log(n))
b) O(n)
c) O(n2)
d) O(1)
79) Assume that you have a hash table in which there are few or no collisions. What is the time required to
remove an element from this hash table?
a) O(n)
b) O(n2)
c) O(1)
d) O(log (n))
80) Which of the following statements about adding an element to a hash table is NOT correct?
a) Add the new element at the beginning of the node sequence in the bucket referenced by the hash code.
b) Check the elements in the bucket to determine if the new element already exists.
c) If the element matches another element in the bucket referenced by the hash code, add the new element to
that bucket.
d) To add an element, its compressed hash code must be computed.
81) If your hashCode function returns a number anywhere in the hash table with equal probability, what is the
likely result?
a) Some objects will be impossible to find.
b) The number of collisions will be high.
c) The get method will run at O(n) complexity.
d) The get method will run at O(1) complexity.
82) Which hash table method(s) will make use of the equals method?
I put
II get
III contains
a) I
b) I and II
c) III
d) I, II and III
83) Which of the following statements about using iterators with hash tables is NOT correct?
a) The iterator must track its position within a node chain in a bucket.
b) The iterator must skip over empty buckets.
c) Two iterators are required: one to traverse the buckets, and another to traverse the nodes within a bucket.
d) The iterator must track the bucket number.
84) What is the time required to iterate over all elements in a hash table of size n?
a) O(log(n))
b) O(n)
c) O(n2)
d) O(1)
85) Assume that you have a hash table in which there are an average number of collisions. What is the time
required to remove an element from this hash table?
a) O(n)
b) O(n2)
c) O(1)
d) O(1)+
86) Assume that you have a hash table in which there are an average number of collisions. What is the time
required to find an element in this hash table?
a) O(n)
b) O(n2)
c) O(1)
d) O(1)+
87) Assume that you have a hash table in which there are an average number of collisions. What is the time
required to add an element to this hash table?
a) O(n)
b) O(n2)
c) O(1)
d) O(1)+
88) Complete the following code, which is intended to add an element to a hash table. Assume that the
computed and compressed hash code is stored in the variable h.
Node newNode = new Node();
newNode.data = x;
_________________
_________________
a)
newNode.next = buckets[h + 1];
buckets[h] = newNode;
b)
newNode.next = buckets[h];
buckets[h + 1] = newNode;
c)
newNode.next = buckets[h];
buckets[h - 1] = newNode;
d)
newNode.next = buckets[h];
buckets[h] = newNode;
89) What type of access does the use of an iterator provide for the elements of a bucket in a hash table?
a) sequential
b) semi-random
c) random
d) sorted
90) The advantage of using the open addressing technique over the separate chaining technique for handling
collisions in a hash table is that open addressing ____.
a) allows for faster addition of elements
b) allows for faster retrieval of elements
c) is simpler in implementation
d) requires less memory storage for the hash table
91) The ___ technique for handling collisions in a hash table with open addressing attempts to place colliding
elements at the next available location in the hash table.
a) sequential placement
b) sequential probing
c) linear placement
d) linear probing
92) Which statement about handling collisions in a hash table using the open addressing technique is correct?
a) A colliding element will always be contiguous to the location in which it would normally be placed.
b) To find an element, you must search from the hash code location until a match or an element with a different
hash code is found.
c) To remove an element, you simply empty the slot at which you find it.
d) There may be some elements with different hash codes that lie on the same probing sequence.
93) Which of the following statements about handling collisions in a hash table using the sequential chaining
and open addressing techniques is NOT correct?
a) The implementation of sequential chaining technique is simpler than the implementation of the open
addressing technique.
b) The sequential chaining technique is simpler to understand than the open addressing technique.
c) The sequential chaining technique requires the storage of links while open addressing does not.
d) The sequential chaining technique requires less memory use than open addressing.
94) Which statement about handling collisions in a hash table using the open addressing technique is NOT
correct?
a) A colliding element may not be contiguous to the location in which it would normally be placed.
b) To find an element, you must search from the hash code location until a match or an empty slot is found.
c) To remove an element, you simply empty the slot at which you find it.
d) there may be some elements with different hash codes that lie on the same probing sequence.