wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Sorting - IV year

Total questions: 20

Worksheet time: 12mins

Name
Class
Date
1.

Consider the following set of integers.

{20,25,57,48,37,12,92,86,33}

If one uses the quick sort algorithm to sort the above set of integers, how many p to completely sort the file?

a)

5

b)

8

c)

3

d)

9

2.

Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step ?

a)

Elements in each half of the array are sorted themselves

b)

Array elements form a heap

c)

Elements in first half are greater than second half

d)

None of these

3.

A newspaper route has recently been computerized. Information about each of the 100 customers is stored in individual records containing first name, last name, and payment due. In writing a computer program to process the customer records, the programmer is uncertain whether to add a procedure to sort the records.If the records are first sorted, what will be the maximum number of comparisons needed with a binary search to find a particular customer's record? ?

a)

7

b)

5

c)

50

d)

100

4.

How can you improve the best case efficiency in bubble sort? (The input is already sorted)

a)

boolean swapped = false;

for(int j=arr.length-1; j>=0 && swapped; j--)

{

swapped = true;

for(int k=0; k<j; k++)

{

if(arr[k] > arr[k+1])

{

int temp = arr[k];

arr[k] = arr[k+1];

arr[k+1] = temp;

swapped = false;

}

}

}

b)

boolean swapped = true;

for(int j=arr.length-1; j>=0 && swapped; j--)

{

swapped = false;

for(int k=0; k<j; k++)

{

if(arr[k] > arr[k+1])

{

int temp = arr[k];

arr[k] = arr[k+1];

arr[k+1] = temp;

}

}

}

c)

boolean swapped = true;

for(int j=arr.length-1; j>=0 && swapped; j--)

{

swapped = false;

for(int k=0; k<j; k++)

{

if(arr[k] > arr[k+1])

{

int temp = arr[k];

arr[k] = arr[k+1];

arr[k+1] = temp;

swapped = true;

}

}

}

d)

boolean swapped = true;

for(int j=arr.length-1; j>=0 && swapped; j--)

{

for(int k=0; k<j; k++)

{

if(arr[k] > arr[k+1])

{

int temp = arr[k];

arr[k] = arr[k+1];

arr[k+1] = temp;

swapped = true;

}

}

}

5.

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

a)

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

b)

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

c)

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

d)

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

6.

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)

O(n^2 Logn)

b)

BO(n^2)

c)

CO(n Logn Logn)

d)

O(nLogn)

7.

The number of elements that can be sorted in o(log n) time using heap sort is

a)

o(1)

b)

o( logn\sqrt{\log n}  )

c)

o(Log n/log log n)

d)

o(Log n)

8.

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:

1 4 0 6 8 11 10 9


Which of the following statement is correct?

a)

The pivot could be either the 6 or the 8.

b)

The pivot could be the 6, but it is not the 8

c)

The pivot is not the 6, but it could be the 8

d)

Neither the 6 nor the 8 is the pivot.

9.

Suppose we are sorting an array of eight integers using heapsort, and we have just finished some heapify (either maxheapify or minheapify) operations. The array now looks like this: 16 14 15 10 12 27 28 How many heapify operations have been performed on root of heap and what type of heap is that?

a)

1 and minheap

b)

2 and maxheap

c)

4 or 5 minheap

d)

5 or 6 max heap

10.

Quicksort is run on two inputs shown below to sort in ascending order taking first element as pivot,


(i) 1, 2, 3,......., n

(ii) n, n-1, n-2,......, 2, 1

a)

C1 < C2

b)

C1 > C2

c)

C1 = C2

d)

We cannot say anything for arbitrary n

11.

Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n(≥ 2) numbers? In the recurrence equations given in the options below, c is a constant.

a)

T(n) = 2T (n/2) + cn

b)

T(n) = 2T (n – 2) + cn

c)

T(n) = T(n – 1) + T(0) + cn

d)

T(n) = T(n/2) + cn

12.

After partial sorting, shell sorting use which sorting to sort the half sorted elements?

a)

No Such Specific Method

b)

Selection Sort

c)

Insertion Sort

d)

Heap Sort as it would work fine with Semi sorted scenario.

13.

In Sorting, Inversion count determines whether it is a best case or average case or best case.

a)

True

b)

False

14.

One of the Greedy Algorithm in Sorting is

a)

Selection

b)

Insertion

c)

Merge

d)

Quick

15.

You have to sort a list L, consisting of a sorted list followed by a few ‘random’ elements. Which of the following sorting method would be most suitable for such a task?

a)

Bubble sort

b)

Selection sort

c)

Quick sort

d)

Insertion sort

16.

You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?

a)

Heap

b)

Merge

c)

Quick

d)

Selection

17.

In quick sort, for sorting n elements, the (n/4)th smallest element is selected as pivot using an O(n) time algorithm. What is the worst case time complexity of the quick sort? (A) (n) (B) () (C) () (D) ()

a)

O(n)

b)

O(nLogn)

c)

O(n^2)

d)

O(n^2 log n)

18.

Which of the following is true about merge sort?

a)

Merge Sort works better than quick sort if data is accessed from slow sequential memory.

b)

Merge Sort is stable sort by nature

c)

Merge sort outperforms heap sort in most of the practical situations.

19.

Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then

a)

T(n) <= 2T(n/5) + n

b)

T(n) <= T(n/5) + T(4n/5) + n

c)

T(n) <= 2T(4n/5) + n

d)

T(n) <= 2T(n/2) + n

20.

Sorting Algorithm that would run in its best version with the time complexity just like a poor searching algorithm is? what is the time complexity?

a)

Heap n

b)

Radix nk

c)

Bubble n

d)

Selection n^2