True/False Indicate whether the
statement is true or false.
|
|
1.
|
Once a String object is created, its length can be
changed.
|
|
2.
|
A Scanner object can be used to read words from the
keyboard, a text file, or a string.
|
|
3.
|
In order to perform a linear search on an array of objects, you should use
the equals method during the search.
|
|
4.
|
When an array becomes full, insertions should not be performed.
|
|
5.
|
When the element type of an array is a reference type or interface, objects of
those types or any subtype (subclass or implementing class) can be directly inserted into the
array.
|
|
6.
|
An ArrayList object does not track its logical
size.
|
|
7.
|
Complexity analysis cannot be applied to recursive methods.
|
|
8.
|
O(n log n) complexity is generally better (more efficient) than
O(n2).
|
|
9.
|
If you have a list of 128 numbers and you perform a binary search on that list,
the maximum number of search steps needed is 8.
|
|
10.
|
The quicksort algorithm cannot be coded using an iterative approach.
|
Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
11.
|
The String class’s ____ method coverts all of
the characters in a String object to lowercase.
a. | toLowerCase | c. | smallChars | b. | lowerCase | d. | lower |
|
|
12.
|
Assuming obj1 and obj2 belong to a class that implements Comparable, the statement obj1.compareTo(obj2); will
return a value of ____ if obj1 is less than obj2.
a. | less than 0 | c. | 0 | b. | greater than 0 | d. | -1 |
|
|
13.
|
Suppose an unsorted array of five integers contains the values {4, 2, 5, 1, 3}.
If a selection sort is performed on this array, the values stored in the array after the second pass
of the sorting algorithm would be ____.
a. | {4, 2, 5, 1, 3} | c. | {1, 2, 3, 5, 4} | b. | {1, 2, 3, 4, 5} | d. | {1, 2, 5, 4, 3} |
|
|
14.
|
Consider the following pseudocode:
For each k from 1
to n - 1 (k is the index of array element to insert) Set itemToInsert to
a[k] Set j to k - 1 (j starts at k - 1 and is decremented
until insertion position is
found) While (insertion position not found) and (not beginning
of array) If
itemToInsert <
a[j] Move
a[j] to index position j +
1 Decrement j by
1
Else The insertion position has
been found itemToInsert should
be positioned at index j + 1
This algorithm represents a(n) ____ sort.
a. | linear | c. | insertion | b. | selection | d. | bubble |
|
|
15.
|
The ArrayList method ____ returns the number of
elements currently in the list.
a. | listSize() | c. | size() | b. | numElements() | d. | length() |
|
|
16.
|
The wrapper class for the double primitive data type is the class ____.
a. | FPWrapper | c. | Double | b. | FloatingPoint | d. | DoubleWrapper |
|
|
17.
|
Which of the following statements would correctly declare an ArrayList object that only holds references to String
objects?
a. | ArrayList[String] list = new
ArrayList[String](); | b. | ArrayList<String>
list = new ArrayList<String>(); | c. | ArrayList list = new
ArrayList(<String>); | d. | ArrayList list = new
ArrayList(); |
|
|
18.
|
Which of the following algorithms is a correct recursive algorithm for summing
n numbers?
a. | sum(n) = n + sum(n - 1) if n > 1 | b. | sum(1) = 1 sum(n) = n + sum(n - 1) if n > 1 | c. | sum(1) = 0 sum(n) = n + sum(n - 1) if n > 1 | d. | sum(1) = 1 sum(n) = n + sum(n - 1) if n >=
1 |
|
|
19.
|
A recursive method with no stopping state will result in ____ recursion.
a. | definite | c. | infinite | b. | incidental | d. | finite |
|
|
20.
|
Computers provide a large storage area known as a ____ at program
startup.
a. | call stack | c. | call queue | b. | method queue | d. | method stack |
|
|
21.
|
A linear search has a complexity of ____.
a. | O(log n) | c. | O(n log n) | b. | O(n) | d. | O(n2) |
|
|
22.
|
The complexity of a recursive algorithm for computing the nth Fibonacci
is ____.
a. | O(n) | c. | O(n3) | b. | O(n2) | d. | O(rn) |
|
|
23.
|
The complexity of the quicksort algorithm is ____ in the best case.
a. | O(log n) | c. | O(n log n) | b. | O(n) | d. | O(n2) |
|
|
24.
|
The maximum run time for merge sort is ____ in best, worst, and average
cases.
a. | O(n) | c. | O(n2) | b. | O(n log
n) | d. | O(n3) |
|
|
25.
|
The class used to create a slider control is the ____ class.
a. | JSlider | c. | Slider | b. | Slide | d. | JSlide |
|