CBSE Class 12
Computer Science
05 Sorting
30
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
Consider the following Bubble Sort pass on the list [5, 1, 4, 2]. What will be the list after the first complete pass?
Medium
Bubble Sort
Reference Code
arr = [5,1,4,2]
for i in range(len(arr)-1):
if arr[i] > arr[i+1]:
arr[i], arr[i+1] = arr[i+1], arr[i]
print(arr)
Answer: [1, 4, 2, 5]
Explanation: Largest element moves to the end during the first pass → [1,4,2,5].
Q-2
After the first iteration of Selection Sort on [29, 10, 14, 37], what will be the array?
Medium
Selection Sort
Answer: [10,29,14,37]
Explanation: Smallest element (10) is selected and swapped with the first element.
Q-3
What will be the list after executing the following insertion sort step?
Medium
Insertion Sort
Reference Code
arr=[8,3,5]
key=arr[1]
j=0
while j>=0 and arr[j]>key:
arr[j+1]=arr[j]
j-=1
arr[j+1]=key
print(arr)
Answer: [3,5,8]
Explanation: 3 is inserted before 8, producing [3,8,5].
Q-4
What will be the output of the following code?
Medium
Bubble Sort
Reference Code
arr=[4,2,7]
for i in range(len(arr)-1):
for j in range(len(arr)-1-i):
if arr[j] > arr[j+1]:
arr[j],arr[j+1]=arr[j+1],arr[j]
print(arr)
Answer: [2,4,7]
Explanation: Bubble sort arranges the list in ascending order.
Q-5
Which characteristic best describes Bubble Sort?
Easy
Bubble Sort
Answer: Repeatedly swaps adjacent elements if they are in wrong order
Explanation: Bubble sort compares adjacent elements and swaps them.
Q-6
Which algorithm repeatedly selects the smallest element and moves it to the sorted portion?
Easy
Selection Sort
Answer: Selection Sort
Explanation: Selection sort finds the minimum element and places it at the beginning.
Q-7
Which sorting algorithm builds the final sorted array one item at a time?
Easy
Insertion Sort
Answer: Insertion Sort
Explanation: Insertion sort inserts elements into the correct position.
Q-8
Which time complexity represents the worst case of Bubble Sort?
Medium
Time Complexity of Algorithms
Answer: O(n²)
Explanation: Bubble sort worst-case complexity is O(n²).
Q-9
What will be the result after one pass of Bubble Sort on [3,2,1]?
Medium
Bubble Sort
Answer: [2,1,3]
Explanation: Largest element moves to the end after one pass.
Q-10
Which complexity represents the best case for Insertion Sort when array is already sorted?
Medium
Time Complexity of Algorithms
Answer: O(n)
Explanation: Insertion sort runs in linear time for sorted input.
Q-11
How many comparisons occur in worst case for Bubble Sort with n elements?
Medium
Time Complexity of Algorithms
Answer: n(n−1)/2
Explanation: Total comparisons are n(n−1)/2.
Q-12
Which sorting algorithm is most suitable when the list is nearly sorted?
Medium
Insertion Sort
Answer: Insertion Sort
Explanation: Insertion sort performs efficiently for nearly sorted lists.
Q-13
What will be printed after the first iteration of Selection Sort?
Medium
Selection Sort
Reference Code
arr=[7,3,9,1]
min_idx=0
for j in range(1,len(arr)):
if arr[j]<arr[min_idx]:
min_idx=j
arr[0],arr[min_idx]=arr[min_idx],arr[0]
print(arr)
Answer: [1,3,9,7]
Explanation: Smallest element (1) swaps with first element.
Q-14
Which factor primarily affects the time complexity of sorting algorithms?
Easy
Time Complexity of Algorithms
Answer: Number of elements
Explanation: Sorting complexity depends mainly on input size.
Q-15
What is the time complexity of Selection Sort in the worst case?
Medium
Selection Sort
Answer: O(n²)
Explanation: Selection sort always performs n² comparisons.
Q-16
Which sorting algorithm repeatedly inserts the current element into the sorted portion?
Easy
Insertion Sort
Answer: Insertion Sort
Explanation: Insertion sort places each element into correct position.
Q-17
What will be printed after executing the following code?
Easy
Introduction
Reference Code
arr=[3,1,2]
arr.sort()
print(arr)
Answer: [1,2,3]
Explanation: Python built-in sort arranges elements in ascending order.
Q-18
How many passes are required in Bubble Sort for an array of size n in worst case?
Medium
Bubble Sort
Answer: n−1
Explanation: Bubble sort requires n−1 passes.
Q-19
Which algorithm has the same time complexity in best, average, and worst cases?
Medium
Selection Sort
Answer: Selection Sort
Explanation: Selection sort always performs n² comparisons.
Q-20
Which notation is used to express algorithm complexity?
Easy
Time Complexity of Algorithms
Answer: Big-O notation
Explanation: Big-O notation describes algorithm efficiency.
Q-21
Which algorithm swaps adjacent elements repeatedly until sorted?
Easy
Bubble Sort
Answer: Bubble Sort
Explanation: Bubble sort swaps adjacent elements.
Q-22
Which algorithm finds minimum element in each pass?
Easy
Selection Sort
Answer: Selection Sort
Explanation: Selection sort repeatedly selects smallest element.
Q-23
What will be printed?
Easy
Introduction
Reference Code
arr=[4,3,2,1]
arr.sort()
print(arr)
Answer: [1,2,3,4]
Explanation: sort() arranges elements in ascending order.
Q-24
Which algorithm is considered stable among the three basic sorts listed?
Hard
Insertion Sort
Answer: Insertion Sort
Explanation: Insertion sort maintains relative order of equal elements.
Q-25
Which operation occurs most frequently in Bubble Sort?
Easy
Bubble Sort
Answer: Comparison of adjacent elements
Explanation: Bubble sort repeatedly compares adjacent elements.
Q-26
Which complexity represents average case of Bubble Sort?
Medium
Time Complexity of Algorithms
Answer: O(n²)
Explanation: Average case is quadratic.
Q-27
Which sorting algorithm shifts elements to insert a key?
Medium
Insertion Sort
Answer: Insertion Sort
Explanation: Insertion sort shifts elements to insert key.
Q-28
Which factor mainly determines algorithm efficiency?
Easy
Time Complexity of Algorithms
Answer: Time complexity
Explanation: Efficiency depends mainly on time complexity.
Q-29
Which sorting method compares adjacent elements and pushes largest element to end each pass?
Easy
Bubble Sort
Answer: Bubble Sort
Explanation: Bubble sort pushes the largest element to the end.
Q-30
Which algorithm performs minimum swaps but many comparisons?
Medium
Selection Sort
Answer: Selection Sort
Explanation: Selection sort minimizes swaps but performs many comparisons.