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
```python
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)
A
[1, 4, 2, 5]
B
[1, 5, 2, 4]
C
[1, 4, 5, 2]
D
[5, 1, 2, 4]
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
A
[29,10,14,37]
B
[10,29,14,37]
C
[14,10,29,37]
D
[10,14,29,37]
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
```python
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)
A
[8,3,5]
B
[3,8,5]
C
[3,5,8]
D
[5,3,8]
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
```python
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)
A
[4,2,7]
B
[2,7,4]
C
[7,4,2]
D
[2,4,7]
Answer: [2,4,7]
Explanation: Bubble sort arranges the list in ascending order.
Q-5
Which characteristic best describes Bubble Sort?
Easy
Bubble Sort
A
Repeatedly swaps adjacent elements if they are in wrong order
B
Selects smallest element and swaps with first
C
Inserts element into sorted portion
D
Divides array into halves
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
A
Bubble Sort
B
Selection Sort
C
Insertion Sort
D
Merge 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
A
Selection Sort
B
Bubble Sort
C
Insertion Sort
D
Quick 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
A
O(n)
B
O(log n)
C
O(n log n)
D
O(n²)
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
A
[2,1,3]
B
[1,2,3]
C
[3,1,2]
D
[2,3,1]
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
A
O(n²)
B
O(n)
C
O(log n)
D
O(n log n)
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
A
n
B
n²
C
n(n−1)/2
D
log n
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
A
Selection Sort
B
Bubble Sort
C
Heap Sort
D
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
```python
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)
A
[1,3,9,7]
B
[3,7,9,1]
C
[7,3,9,1]
D
[1,7,9,3]
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
A
Number of variables
B
Number of elements
C
Programming language
D
Operating system
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
A
O(n log n)
B
O(n)
C
O(n²)
D
O(log n)
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
A
Selection Sort
B
Bubble Sort
C
Heap Sort
D
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
```python
arr=[3,1,2]
arr.sort()
print(arr)
A
[1,2,3]
B
[3,1,2]
C
[2,1,3]
D
[3,2,1]
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
A
n
B
n−1
C
n²
D
log n
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
A
Bubble Sort
B
Insertion Sort
C
Selection Sort
D
Merge 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
A
Theta notation
B
Lambda notation
C
Delta notation
D
Big-O notation
Answer: Big-O notation
Explanation: Big-O notation describes algorithm efficiency.
Q-21
Which algorithm swaps adjacent elements repeatedly until sorted?
Easy
Bubble Sort
A
Bubble Sort
B
Selection Sort
C
Insertion Sort
D
Heap Sort
Answer: Bubble Sort
Explanation: Bubble sort swaps adjacent elements.
Q-22
Which algorithm finds minimum element in each pass?
Easy
Selection Sort
A
Insertion Sort
B
Selection Sort
C
Bubble Sort
D
Quick Sort
Answer: Selection Sort
Explanation: Selection sort repeatedly selects smallest element.
Q-23
What will be printed?
Easy
Introduction
Reference Code
```python
arr=[4,3,2,1]
arr.sort()
print(arr)
A
[4,3,2,1]
B
[3,4,1,2]
C
[1,2,3,4]
D
[2,3,4,1]
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
A
Selection Sort
B
Quick Sort
C
Heap Sort
D
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
A
Comparison of adjacent elements
B
Division of arrays
C
Tree traversal
D
Hash calculation
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
A
O(log n)
B
O(n²)
C
O(n)
D
O(n log n)
Answer: O(n²)
Explanation: Average case is quadratic.
Q-27
Which sorting algorithm shifts elements to insert a key?
Medium
Insertion Sort
A
Selection Sort
B
Bubble Sort
C
Insertion Sort
D
Heap 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
A
Code length
B
Variable names
C
Output format
D
Time complexity
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
A
Bubble Sort
B
Insertion Sort
C
Selection Sort
D
Merge 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
A
Bubble Sort
B
Selection Sort
C
Insertion Sort
D
Quick Sort
Answer: Selection Sort
Explanation: Selection sort minimizes swaps but performs many comparisons.
◀
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
▶