wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit -2 Control Statements and Sorting Algorithms

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

Which of the following is NOT a control statement in C/C++?

a)

if-else

b)

switch

c)

for

d)

class

2.

What is the main purpose of a loop invariant?

a)

To ensure faster execution

b)

To prove correctness of a loop

c)

To reduce memory usage

d)

To determine loop termination condition

3.

A loop invariant must hold:

a)

Only before the loop starts

b)

Before and after every iteration

c)

Only after the loop ends

d)

Randomly during execution

4.

Loop invariants are mainly used in:

a)

Compiler optimization

b)

Algorithm correctness proofs

c)

Data compression

d)

File handling

5.

If a while loop runs n times, proving correctness requires:

a)

Base case, inductive step

b)

Just loop termination

c)

Big-O analysis

d)

Deadlock freedom

6.

The "termination condition" in a loop guarantees:

a)

No segmentation fault

b)

Loop eventually ends

c)

Algorithm is stable

d)

Minimum space complexity

7.

Which of the following is a variant function used in correctness proofs?

a)

A function that strictly decreases with each iteration

b)

A function that increases arbitrarily

c)

A constant function

d)

A random number generator

8.

The correctness of sorting algorithms is usually proven using:

a)

Divide and conquer

b)

Loop invariants

c)

Heap property

d)

Hashing

9.

Which control statement can cause infinite loops if used incorrectly?

a)

break

b)

continue

c)

while

d)

switch

10.

Partial correctness means:

a)

Algorithm always halts with correct output

b)

If algorithm halts, output is correct

c)

Algorithm never halts

d)

Algorithm is both fast and correct

11.

Best-case time complexity of Bubble Sort is:

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

O(log n)

12.

Worst-case time complexity of Selection Sort is:

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

O(log n)

13.

Insertion Sort is efficient for:

a)

Very large datasets

b)

Small or nearly sorted datasets

c)

Random datasets

d)

None of these

14.

Which sorting algorithm is in-place and stable?

a)

Selection Sort

b)

Bubble Sort

c)

Insertion Sort

d)

Both B and C

15.

Heap Sort is based on:

a)

Binary Search Tree

b)

Binary Heap

c)

AVL Tree

d)

Linked List

16.

Height of a binary heap with n elements is:

a)

O(n)

b)

O(log n)

c)

O(√n)

d)

O(1)

17.

Which sorting algorithm repeatedly selects the minimum element and places it at the beginning?

a)

Bubble Sort

b)

Selection Sort

c)

Heap Sort

d)

Insertion Sort

18.

The time complexity of Heap Sort is:

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

O(log n)

19.

Which of the following sorting algorithms is NOT comparison-based?

a)

Heap Sort

b)

Quick Sort

c)

Counting Sort

d)

Insertion Sort

20.

The worst-case number of comparisons in Bubble Sort is:

a)

n

b)

c)

log n

d)

n log n

21.

Counting Sort works only for:

a)

Arbitrary integers

b)

Negative numbers

c)

Integers in small range

d)

Floating-point numbers

22.

Space complexity of Counting Sort is:

a)

O(1)

b)

O(n)

c)

O(k + n), where k = range of numbers

d)

O(log n)

23.

Radix Sort depends on:

a)

Heap property

b)

Stable sorting of digits

c)

Divide and conquer

d)

Binary search

24.

Time complexity of Radix Sort is:

a)

O(n²)

b)

O(n log n)

c)

O(d·(n + k)) where d = digits, k = range per digit

d)

O(n)

25.

Bucket Sort is best applied to:

a)

Uniformly distributed real numbers in [0,1)

b)

Random integers

c)

Strings

d)

Sparse matrices

26.

The stability of Radix Sort is maintained by using:

a)

Quick Sort

b)

Merge Sort

c)

Stable version of Counting Sort

d)

Heap Sort

27.

Counting Sort fails for large ranges because:

a)

It becomes unstable

b)

It uses excessive space

c)

It doesn't terminate

d)

It requires recursion

28.

Bucket Sort average-case complexity is:

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

O(log n)

29.

Which of the following is NOT a linear time sorting algorithm?

a)

Radix Sort

b)

Counting Sort

c)

Merge Sort

d)

Bucket Sort

30.

Which sorting algorithm is most suitable for sorting strings of equal length?

a)

Bubble Sort

b)

Radix Sort

c)

Selection Sort

d)

Heap Sort

31.

What is the output? int arr[] = {5, 2, 4}; bubbleSort(arr, 3); // standard bubble sort printf("%d", arr[0]);

a)

2

b)

4

c)

5

d)

Undefined

32.

Number of swaps in Selection Sort for array {3,1,2}:

a)

1

b)

2

c)

3

d)

0

33.

Insertion Sort on {4,3,2,1} gives how many comparisons?

a)

3

b)

6

c)

10

d)

4

34.

If Bubble Sort is modified to stop when no swaps occur in a pass, the best-case complexity becomes:

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

O(log n)

35.

Output of: arr = [5,1,4,2] insertionSort(arr) print(arr[-1])

a)

1

b)

2

c)

4

d)

5

36.

Selection Sort always performs how many comparisons for array size n?

a)

O(n²)

b)

O(n log n)

c)

O(n)

d)

Depends on input

37.

Bubble Sort is stable because:

a)

It swaps only when strictly greater

b)

It uses extra memory

c)

It compares adjacent elements

d)

None of these

38.

After inserting 50 into a max-heap {70, 60, 30}, root is:

a)

30

b)

50

c)

60

d)

70

39.

Heapify operation complexity is:

a)

O(n)

b)

O(log n)

c)

O(1)

d)

O(n log n)

40.

In Heap Sort, building a max heap takes:

a)

O(n log n)

b)

O(n)

c)

O(log n)

d)

O(n²)

41.

Output after one delete-max from {90,70,50,40}:

a)

{70,40,50}

b)

{40,50,70}

c)

{70,90,50}

d)

{90,50,40}

42.

Heap Sort is:

a)

Stable

b)

Not stable

c)

Sometimes stable

d)

Stable for strings only

43.

Counting Sort on {4,2,2,8} outputs:

a)

{2,2,4,8}

b)

{8,4,2,2}

c)

{4,2,8,2}

d)

None

44.

Space required for Counting Sort of 1 million integers in range [1,100]:

a)

O(1,000,000)

b)

O(100)

c)

O(1,000,100)

d)

O(log n)

45.

Radix Sort on {170, 45, 75, 90} (LSD) after sorting by units digit:

a)

{170, 90, 45, 75}

b)

{45, 75, 170, 90}

c)

{90, 170, 45, 75}

d)

{75, 45, 90, 170}

46.

Bucket Sort with 10 buckets for [0.25,0.36,0.58,0.41], element 0.36 goes in bucket index:

a)

2

b)

3

c)

4

d)

5

47.

Radix Sort is applied digit by digit using:

a)

Stable sorting method

b)

Quick Sort

c)

Heap Sort

d)

Binary Search

48.

Output of Counting Sort for negative numbers is:

a)

Always correct

b)

Incorrect without modification

c)

Sometimes correct

d)

Undefined

49.

If radix = 10 and d = 3 (3-digit numbers), time complexity of Radix Sort is:

a)

O(3n) = O(n)

b)

O(n log n)

c)

O(n²)

d)

O(3n log n)

50.

Bucket Sort worst case occurs when:

a)

All elements go into one bucket

b)

Elements are uniformly distributed

c)

Buckets are empty

d)

Buckets are more than n