WorksheetsQuiz 2 DS1D
Total questions: 12
Worksheet time: 15mins
Which of the following growth-rate functions grows the slowest in value?
1
n
n2
log2 n
An algorithm’s execution time is related to the number of ______ it requires.
parameters
test data sets
data fields
operations
The ______ compares adjacent items and exchanges them if they are out of order.
selection sort
binary search
bubble sort
quick sort
Given the following queue operations on an empty existing queue called nameQueue.
nameQueue.enqueue(Bob)
nameQueue.enqueue(Bill)
nameQueue.enqueue(Bud)
nameQueue.dequeue()
nameQueue.enqueue(Boo)
What is now the contents of the queue (with front of the queue listed leftmost)?
Bob, Bill, Bud
Bob, Bud, Boo
Bill, Bud, Boo
Boo, Bud, Bill
For large arrays, the insertion sort is prohibitively inefficient.
True
False
For relatively small problem, the quick sort can be slower than the insertion sort.
True
False
Which of the following is NOT a similarity between a stack and a queue as described by the text?
Both have an isEmpty method
Both can retrieve an item from any position
Both can insert an entry at one end of the structure
Both can retrieve an entry from one end of the structure
Which of the following can be used to compare two algorithms?
growth rates of the two algorithms
implementations of the two algorithms
test data used to test programs which implement the two algorithms
computers on which programs which implement the two algorithms are run
Given the following array:
4 15 8 3 28 21
which of the following represents the array after the second swap of the selection sort?
4 3 8 15 21 28
4 15 8 3 21 28
3 4 8 15 21 28
21 4 3 8 15 28
Given the fact that a selection sort of n items requires
n2/2 + 5 * n/2 – 3 major operations, the selection sort is ______.
O(1)
O(n)
O(n2)
O(log2 n)
What is the name of the sorting algorithm that is implemented by the code given below?
void sort(int a[], int size) {
int i;
int last_swap;
int ncomparison = size-1;
while(ncomparison != 0) {
last_swap = 0;
for(i=0; i<ncomparison; i++) {
if(a[i] > a[i+1]) {
swap(a[i], a[i+1]);
last_swap = i;
}
}
ncomparison = last_swap;
}
}
selection sort
bubble sort
merge sort
quick sort
How does the isEmpty method of ArrayQueue class return the proper value?
return count == 0;
return front != back;
return front/ back == 0;
return count < DEFAULT_CAPACITY;
