Some Sample Multiple Choice Questions for Exam #3
Solutions
1) How many swaps are performed when the array below is sorted using
a Bubble Sort?
8
7
6
5
4
3
2
1
A) 8
B) 15
C) 21
D) 28
E) NOTA
The first iteration performs 7 swaps, since 8 is swapped each time.
The next iteration performs 6 swaps, etc. Thus, our total is
7+6+5+4+3+2+1 = 28 swaps.
2) What is the maximum number of swaps performed by a selection sort
of 50 elements?
A) 49
B) 99
C) 1249
D) 1250
E) 2500
Selection Sort only makes one swap for each iteration. After 49
iterations, the last element is guaranteed to be in place as well, so
this is the maximum.
3) What is the bestcase runtime of Insertion Sort on n elements?
A) O(lgn)
B) O(n)
C) O(nlgn)
D) O(n
2
)
E) NOTA
This is when insertion sort is run on a sorted list and each item is
“looked at” once, which is O(n) time.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
contents of the array right after the 3
rd
call to the Merge function?
8
3
4
6
1
7
5
2
A) 8
3
4
6
1
7
5
2
B) 1
2
3
4
5
6
7
8
C) 3
4
6
8
1
7
2
5
D) 3
4
6
8
1
2
5
7
E) NOTA
The correct answer is 3 4 6 8 1 7 5 2. Basically the first three Merges
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Guha
 Computer Science, Bubble Sort, Quick Sort, Array, Run time

Click to edit the document details