Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 2 DS1D

Total questions: 12

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following growth-rate functions grows the slowest in value?

a)

1

b)

n

c)

n2

d)

log2 n

2.

An algorithm’s execution time is related to the number of ______ it requires.

a)

parameters

b)

test data sets

c)

data fields

d)

operations

3.

The ______ compares adjacent items and exchanges them if they are out of order.

a)

selection sort

b)

binary search

c)

bubble sort

d)

quick sort

4.

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)?

a)

Bob, Bill, Bud

b)

Bob, Bud, Boo

c)

Bill, Bud, Boo

d)

Boo, Bud, Bill

5.

For large arrays, the insertion sort is prohibitively inefficient.

a)

True

b)

False

6.

For relatively small problem, the quick sort can be slower than the insertion sort.

a)

True

b)

False

7.

Which of the following is NOT a similarity between a stack and a queue as described by the text?

a)

Both have an isEmpty method

b)

Both can retrieve an item from any position

c)

Both can insert an entry at one end of the structure

d)

Both can retrieve an entry from one end of the structure

8.

Which of the following can be used to compare two algorithms?

a)

growth rates of the two algorithms

b)

implementations of the two algorithms

c)

test data used to test programs which implement the two algorithms

d)

computers on which programs which implement the two algorithms are run

9.

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?

a)

4 3 8 15 21 28

b)

4 15 8 3 21 28

c)

3 4 8 15 21 28

d)

21 4 3 8 15 28

10.

Given the fact that a selection sort of n items requires

n2/2 + 5 * n/2 – 3 major operations, the selection sort is ______.

a)

O(1)

b)

O(n)

c)

O(n2)

d)

O(log2 n)

11.

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;

}

}

a)

selection sort

b)

bubble sort

c)

merge sort

d)

quick sort

12.

How does the isEmpty method of ArrayQueue class return the proper value?

a)

return count == 0;

b)

return front != back;

c)

return front/ back == 0;

d)

return count < DEFAULT_CAPACITY;