NEW
Font size
WorksheetsUnit -2 Control Statements and Sorting Algorithms
Total questions: 50
Worksheet time: 25mins
Which of the following is NOT a control statement in C/C++?
if-else
switch
for
class
What is the main purpose of a loop invariant?
To ensure faster execution
To prove correctness of a loop
To reduce memory usage
To determine loop termination condition
A loop invariant must hold:
Only before the loop starts
Before and after every iteration
Only after the loop ends
Randomly during execution
Loop invariants are mainly used in:
Compiler optimization
Algorithm correctness proofs
Data compression
File handling
If a while loop runs n times, proving correctness requires:
Base case, inductive step
Just loop termination
Big-O analysis
Deadlock freedom
The "termination condition" in a loop guarantees:
No segmentation fault
Loop eventually ends
Algorithm is stable
Minimum space complexity
Which of the following is a variant function used in correctness proofs?
A function that strictly decreases with each iteration
A function that increases arbitrarily
A constant function
A random number generator
The correctness of sorting algorithms is usually proven using:
Divide and conquer
Loop invariants
Heap property
Hashing
Which control statement can cause infinite loops if used incorrectly?
break
continue
while
switch
Partial correctness means:
Algorithm always halts with correct output
If algorithm halts, output is correct
Algorithm never halts
Algorithm is both fast and correct
Best-case time complexity of Bubble Sort is:
O(n²)
O(n log n)
O(n)
O(log n)
Worst-case time complexity of Selection Sort is:
O(n²)
O(n log n)
O(n)
O(log n)
Insertion Sort is efficient for:
Very large datasets
Small or nearly sorted datasets
Random datasets
None of these
Which sorting algorithm is in-place and stable?
Selection Sort
Bubble Sort
Insertion Sort
Both B and C
Heap Sort is based on:
Binary Search Tree
Binary Heap
AVL Tree
Linked List
Height of a binary heap with n elements is:
O(n)
O(log n)
O(√n)
O(1)
Which sorting algorithm repeatedly selects the minimum element and places it at the beginning?
Bubble Sort
Selection Sort
Heap Sort
Insertion Sort
The time complexity of Heap Sort is:
O(n²)
O(n log n)
O(n)
O(log n)
Which of the following sorting algorithms is NOT comparison-based?
Heap Sort
Quick Sort
Counting Sort
Insertion Sort
The worst-case number of comparisons in Bubble Sort is:
n
n²
log n
n log n
Counting Sort works only for:
Arbitrary integers
Negative numbers
Integers in small range
Floating-point numbers
Space complexity of Counting Sort is:
O(1)
O(n)
O(k + n), where k = range of numbers
O(log n)
Radix Sort depends on:
Heap property
Stable sorting of digits
Divide and conquer
Binary search
Time complexity of Radix Sort is:
O(n²)
O(n log n)
O(d·(n + k)) where d = digits, k = range per digit
O(n)
Bucket Sort is best applied to:
Uniformly distributed real numbers in [0,1)
Random integers
Strings
Sparse matrices
The stability of Radix Sort is maintained by using:
Quick Sort
Merge Sort
Stable version of Counting Sort
Heap Sort
Counting Sort fails for large ranges because:
It becomes unstable
It uses excessive space
It doesn't terminate
It requires recursion
Bucket Sort average-case complexity is:
O(n²)
O(n log n)
O(n)
O(log n)
Which of the following is NOT a linear time sorting algorithm?
Radix Sort
Counting Sort
Merge Sort
Bucket Sort
Which sorting algorithm is most suitable for sorting strings of equal length?
Bubble Sort
Radix Sort
Selection Sort
Heap Sort
What is the output? int arr[] = {5, 2, 4}; bubbleSort(arr, 3); // standard bubble sort printf("%d", arr[0]);
2
4
5
Undefined
Number of swaps in Selection Sort for array {3,1,2}:
1
2
3
0
Insertion Sort on {4,3,2,1} gives how many comparisons?
3
6
10
4
If Bubble Sort is modified to stop when no swaps occur in a pass, the best-case complexity becomes:
O(n²)
O(n log n)
O(n)
O(log n)
Output of: arr = [5,1,4,2] insertionSort(arr) print(arr[-1])
1
2
4
5
Selection Sort always performs how many comparisons for array size n?
O(n²)
O(n log n)
O(n)
Depends on input
Bubble Sort is stable because:
It swaps only when strictly greater
It uses extra memory
It compares adjacent elements
None of these
After inserting 50 into a max-heap {70, 60, 30}, root is:
30
50
60
70
Heapify operation complexity is:
O(n)
O(log n)
O(1)
O(n log n)
In Heap Sort, building a max heap takes:
O(n log n)
O(n)
O(log n)
O(n²)
Output after one delete-max from {90,70,50,40}:
{70,40,50}
{40,50,70}
{70,90,50}
{90,50,40}
Heap Sort is:
Stable
Not stable
Sometimes stable
Stable for strings only
Counting Sort on {4,2,2,8} outputs:
{2,2,4,8}
{8,4,2,2}
{4,2,8,2}
None
Space required for Counting Sort of 1 million integers in range [1,100]:
O(1,000,000)
O(100)
O(1,000,100)
O(log n)
Radix Sort on {170, 45, 75, 90} (LSD) after sorting by units digit:
{170, 90, 45, 75}
{45, 75, 170, 90}
{90, 170, 45, 75}
{75, 45, 90, 170}
Bucket Sort with 10 buckets for [0.25,0.36,0.58,0.41], element 0.36 goes in bucket index:
2
3
4
5
Radix Sort is applied digit by digit using:
Stable sorting method
Quick Sort
Heap Sort
Binary Search
Output of Counting Sort for negative numbers is:
Always correct
Incorrect without modification
Sometimes correct
Undefined
If radix = 10 and d = 3 (3-digit numbers), time complexity of Radix Sort is:
O(3n) = O(n)
O(n log n)
O(n²)
O(3n log n)
Bucket Sort worst case occurs when:
All elements go into one bucket
Elements are uniformly distributed
Buckets are empty
Buckets are more than n
