wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Sorting2

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

What is recurrence for worst case of QuickSort and what is the time complexity in Worst case?

a)

A. Recurrence is T(n) = T(n-2) + O(n) and time complexity is O(n^2)

b)

B. Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n^2)

c)

C. Recurrence is T(n) = 2T(n/2) + O(n) and time complexity is O(nLogn)

d)

D. Recurrence is T(n) = T(n/10) + T(9n/10) + O(n) and time complexity is O(nLogn)

2.

What is an external sorting algorithm?

a)

A. Algorithm that uses tape or disk during the sort

b)

B. Algorithm that uses main memory during the sort

c)

C. Algorithm that involves swapping

d)

D. Algorithm that are considered ‘in place’

3.

If the number of records to be sorted is small, then …… sorting can be efficient.

a)

A. Merge

b)

B. Heap

c)

C. Selection

d)

D. Bubble

4.

.Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort.

a)

A. O(n^2 Logn)

b)

B. O(n^2)

c)

C. O(n Logn Logn)

d)

D. O(nLogn)

5.

The complexity of sorting algorithm measures the …… as a function of the number n of items to be sorter.

a)

A. average time

b)

B. running time

c)

C. average-case complexity

d)

D. case-complexity

6.

Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this:

2 5 1 7 9 12 11 10

Which statement is correct?

a)

A. The pivot could be either the 7 or the 9.

b)

B. The pivot could be the 7, but it is not the 9

c)

C. The pivot is not the 7, but it could be the 9

d)

D. Neither the 7 nor the 9 is the pivot.

7.

.Consider the situation in which assignment operation is very costly. Which of the following sorting algorithm should be performed so that the number of assignment operations is minimized in general?

a)

A. Insertion sort

b)

B. Selection sort

c)

C. Heap sort

d)

D. None

8.

What is the advantage of selection sort over other sorting techniques?

a)

a) It requires no additional storage space

b)

b) It is scalable

c)

c) It works best for inputs which are already sorted

d)

d) It is faster than any other sorting technique

9.

What is the average case complexity of selection sort?

a)

A. O(nlogn)

b)

B. O(logn)

c)

C. O(n)

d)

D. O(n2)

10.

What is the worst case complexity of bubble sort?

a)

A. O(nlogn)

b)

B. O(logn)

c)

C. O(n)

d)

D. O(n2)

11.

The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array?

a)

A. 4

b)

B. 2

c)

C. 1

d)

D. 0

12.

What is a randomized QuickSort?

a)

A. The leftmost element is chosen as the pivot

b)

B. The rightmost element is chosen as the pivot

c)

C. Any element in the array is chosen as the pivot

d)

D. A random number is generated which is used as the pivot

13.

Running merge sort on an array of size n which is already sorted is

a)

a) O(n)

b)

b) O(nlogn)

c)

c) O(n2)

d)

d) None