wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Sorting algorithms I

Total questions: 21

Worksheet time: 12mins

Name
Class
Date
1.

What is meant by an in-place sorting algorithm?

a)

The input is already sorted and in-place

b)

It requires additional storage

c)

It needs O(1) memory to create auxiliary locations

d)

It requires additional space

2.

Which of the following is an in-place sorting algorithm?

a)

Selection sort

b)

Insertion sort

c)

Bubble sort

d)

All

3.

Which of the following sorting algorithms is best used when the array is nearly sorted to begin with?

a)

Selection sort

b)

Insertion sort

c)

Bubble sort

d)

None of the above

4.

What is the worst case complexity of selection sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(𝐧𝟐)

5.

Select the appropriate code that performs selection sort.

a)

b)

c)

d)

6.

What is the average case complexity of selection sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(𝐧𝟐)

7.

What is the disadvantage of selection sort?

a)

What is the disadvantage of selection sort?

b)

It is not scalable

c)

It can be used for small keys

d)

It takes linear time to sort the elements

8.

How many passes does an insertion sorting algorithm consist of?

a)

N

b)

N-1

c)

N+1

d)

N2

9.

What is the average case complexity of an insertion sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(𝐧𝟐)

10.

Any algorithm that sorts by exchanging adjacent elements require O(N2) on average.

a)

True

b)

False

11.

What is the running time of an insertion sort algorithm if the input is presorted?

a)

O(n2)

b)

O(nlogn)

c)

O(n)

d)

O(logn)

12.

What will be the number of passes to sort the elements using insertion sort?

14, 12,16, 6, 3, 10

a)

6

b)

5

c)

7

d)

1

13.

For the following question, how will the array elements look like after second pass?

34, 8, 64, 51, 32, 21

a)

8, 21, 32, 34, 51, 64

b)

8, 32, 34, 51, 64, 21

c)

8, 34, 51, 64, 32, 21

d)

8, 34, 64, 51, 32, 21

14.

For the best case input, the running time of an insertion sort algorithm is?

a)

Linear

b)

Binary

c)

Quadratic

d)

Depends on the input

15.

Which of the following examples represent the worst case input for an insertion sort?

a)

Array in sorted order

b)

Array sorted in reverse order

c)

Normal unsorted array

d)

Large array

16.

What is the worst case complexity of bubble sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(𝐧𝟐)

17.

Select the appropriate code that performs bubble sort.

a)

b)

c)

d)

18.

What is the average case complexity of bubble sort?

a)

O(nlogn)

b)

O(logn)

c)

O(n)

d)

O(𝐧𝟐)

19.

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)

4

b)

2

c)

1

d)

0

20.

The given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and selection sort respectively are:

a)

5 and 4

b)

4 and 5

c)

2 and 4

d)

2 and 5

21.

What is the advantage of selection sort, insertion sort and bubble sort over other sorting algorithms?

a)

They are scalable

b)

They do not require additional storage space

c)

They work best for inputs which are already sorted

d)

They are faster than any other sorting techniques