Quiz 4 Flashcards

1
Q

Maps allocate keys to values and cannot contain duplicate keys, i.e., the key-to-value mapping is a _________ mapping.

A

One-to-one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack method ________ looks at the top element of a stack without removing that element.

A

Peek

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A recursive method ________.

A

Can be called indirectly through another method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When a recursive method is called to solve a problem, the method actually is capable of solving only the simplest case(s), or ________.

A

The base case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Iterator method ________ determines whether the Collection contains more elements.

A

hasNext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In recursive backtracking, if one set of recursive calls does not result in a solution to the problem, what happens?

A

The program returns to a previous decision point and makes a different decision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Map method ________ is used to determine whether a map contains a mapping for the specified key.

A

containsKey

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Collections method ________ returns true if two Collections have no elements in common.

A

disjoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The collections framework algorithms are ________, i.e., each of these algorithms can operate on objects that implement specified interfaces without concern for the underlying implementations.

A

Polymorphic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Algorithm ________ randomly orders a List’s elements.

A

Shuffle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Recursion often is preferable to iteration because ________.

A

It models the problem more logically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If the desired Object is not found, binarySearch returns ________.

A

Negative value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which statement is false?
A) A collection is an object that can hold references to other objects.
B) The collection interfaces declare the operations that can be performed on each type of collection.
C) Unfortunately, collections discourage software reuse because they are non-portable.
D) Collections are carefully constructed for rapid execution and efficient use of memory.

A

C

Collections encourage software reuse because they are portable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which statement is false?
A) Each primitive type has a corresponding type-wrapper class.
B) The type-wrapper classes enable you to manipulate primitive-type values as objects.
C) Type-wrapper classes are final, so you cannot extend them.
D) The methods for primitive types correspond to the methods for the corresponding type-wrapper classes.

A

D

Primitive types don’t have methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When the recursion step executes ___

A

The original call to the method is still active

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which statement is false?
A) A List is an ordered Collection.
B) A List cannot contain duplicate elements.
C) A List is sometimes called a sequence.
D) Lists are zero based.

A

B

A list can contain duplicates

17
Q

If no elements are in the Stack, method pop throws an ________.

A

EmptyStackException

18
Q
Which of the following performs a  boxing conversion?
A) int x = 7;
B) Integer x = 7;
C) Neither of the above.
D) Both of the above.
A

B

19
Q
Which of the following performs an  unboxing conversion? Assume  x refers to an  Integer object.
A) int y = x;
B) Integer y = x;
C) Neither of the above.
D) Both of the above.
A

A

20
Q

The recursion step should ________.

A

Call a fresh copy of the recursive method to work on a smaller problem

21
Q

Collections method ________ returns a Comparator object that orders the collection’s elements in reverse order.

A

ReverseOrder

22
Q

A(n) ________ allows a program to walk through the collection and remove elements from the collection.

A

Iterator

23
Q

Class Collections provides algorithms for reversing, filling and copying _______.

A

Lists

24
Q

Recursion is often less efficient than iteration because _____.

A

it can cause an explosion of method calls. 100%

25
Q

More which statement is false?
A) A ListIterator accesses the elements of a List.
B) Class ArrayList is a fixed-size array.
C) A LinkedList is a linked list implementation of a List.
D) ArrayLists execute faster than Vectors because they are not thread safe.

A

B

Class ArrayList is not a fixed length

26
Q

Which is false

A When a List is backed up with an array, any modifications made through the List view change the array.
B) When a List is backed up with an array, any modifications made to the array change the List view.
C) The only operation permitted on the view returned by Arrays method asList is delete, which deletes the value from the view and the backing array.
D) Adding elements to the view returned by Arrays method asList results in an UnsupportedOperationException.

A

C

The only operation allowed for Arrays’ method asList() is set

27
Q

Which is false

A) Java does not guarantee which item will be found first when a binarySearch is performed on a List containing multiple elements equivalent to the search key.
B) If the search key is found, method binarySearch returns the List index (position relative to 1) of the element containing the search key.
C) The binary search algorithm is fast.
D) Method binarySearch takes a List as the first argument.

A

B

If it is found, index is returned. If the object is not found, binarySearch returns a negative value by calculating the insertion point and making its sign negative. Then it subtracts 1 from the insertion point to obtain the return value which guarantees it will return a positive number if the object is found

28
Q

Which is false?

D) A) Queue is a new collection interface introduced in J2SE 5.0.
B) Queue and PriorityQueue are included in the java.util package.
C) PriorityQueue orders elements in increasing order, so that smallest value will be the first element removed from PriorityQueue.
D) Queue extends interface Collection.

A

C

The largest element would be removed first

29
Q

Which is false?

E) A) SortedSet extends Set.
B) Class SortedSet implements TreeSet.
C) When a HashSet is constructed, it removes any duplicates in the Collection.
D) By definition, a Set object does not contain any duplicates.

A

B

30
Q

Which is false?

F) A) Hashing facilitates high-speed storing and retrieval of data.
B) Two different data items can hash to the same cell; this is called a collision.
C) A load factor of 0.5 usually results in good hashing performance, but less efficient utilization of memory.
D) A load factor of 1.0 usually results in good hashing performance, but less efficient utilization of memory.

A

D

31
Q

Which is false?

G) A) All built-in collections are synchronized.
B) Concurrent access to a Collection by multiple threads could cause indeterminate results or fatal errors.
C) To prevent potential threading problems, synchronization wrappers are used around collection classes that might be accessed by multiple threads.
D) A synchronization wrapper class receives method calls, adds some functionality for thread safety and then delegates the calls to the wrapped class.

A

A

32
Q

Which is false?

H) A) The Collections API provides a set of public static methods for converting collections to unmodifiable versions.
B) Unmodifable wrappers throw ModificationExceptions if attempts are made to modify the collection.
C) You can use an unmodifiable wrapper to create a collection that offers read-only access to others while allowing read-write access to yourself.
D) You can create the kind of collection mentioned in part (c) simply by giving others a reference to the unmodifiable wrapper while you also retain a reference to the wrapped collection itself.

A

B