CBSE Class XII Computer Science – Chapter 5: Sorting (Bubble, Selection & Insertion Sort)
Section A: Multiple Choice Questions (MCQs)
1. Sorting is the process of —
·
a) Finding data
·
b) Arranging data in order
·
c) Copying data
·
d) Deleting data
Answer: b) Arranging data in order
2. Bubble sort repeatedly —
·
a) Divides the list
·
b) Swaps adjacent elements
·
c) Inserts new elements
·
d) Deletes smallest element
Answer: b) Swaps adjacent elements
3. In Bubble sort, total number of passes for n elements is
—
·
a) n
·
b) n-1
·
c) n+1
·
d) n²
Answer: b) n-1
4. The element which 'bubbles up' in Bubble sort is —
·
a) Smallest element
·
b) Largest element
·
c) Middle element
·
d) Random element
Answer: b) Largest element
5. Selection sort finds the —
·
a) Largest element each time
·
b) Smallest element each time
·
c) Middle element
·
d) Random element
Answer: b) Smallest element each time
6. Insertion sort divides the list into —
·
a) Equal halves
·
b) Sorted and unsorted parts
·
c) Random parts
·
d) Two equal halves
Answer: b) Sorted and unsorted parts
7. In Bubble sort, when no swapping occurs in a pass, the
list is —
·
a) Still unsorted
·
b) Completely sorted
·
c) Partially sorted
·
d) Needs another pass
Answer: b) Completely sorted
8. Which of the following has nested loops in its algorithm?
·
a) Bubble sort
·
b) Selection sort
·
c) Insertion sort
·
d) All of these
Answer: d) All of these
9. The time complexity of Bubble sort is —
·
a) O(1)
·
b) O(n)
·
c) O(n²)
·
d) O(log n)
Answer: c) O(n²)
10. Selection sort performs swapping —
·
a) Frequently
·
b) After every comparison
·
c) Once in each pass
·
d) Randomly
Answer: c) Once in each pass
11. Sorting is the process of —
·
a) Finding data
·
b) Arranging data in order
·
c) Copying data
·
d) Deleting data
Answer: b) Arranging data in order
12. Bubble sort repeatedly —
·
a) Divides the list
·
b) Swaps adjacent elements
·
c) Inserts new elements
·
d) Deletes smallest element
Answer: b) Swaps adjacent elements
13. In Bubble sort, total number of passes for n elements is
—
·
a) n
·
b) n-1
·
c) n+1
·
d) n²
Answer: b) n-1
14. The element which 'bubbles up' in Bubble sort is —
·
a) Smallest element
·
b) Largest element
·
c) Middle element
·
d) Random element
Answer: b) Largest element
15. Selection sort finds the —
·
a) Largest element each time
·
b) Smallest element each time
·
c) Middle element
·
d) Random element
Answer: b) Smallest element each time
16. Insertion sort divides the list into —
·
a) Equal halves
·
b) Sorted and unsorted parts
·
c) Random parts
·
d) Two equal halves
Answer: b) Sorted and unsorted parts
17. In Bubble sort, when no swapping occurs in a pass, the
list is —
·
a) Still unsorted
·
b) Completely sorted
·
c) Partially sorted
·
d) Needs another pass
Answer: b) Completely sorted
18. Which of the following has nested loops in its
algorithm?
·
a) Bubble sort
·
b) Selection sort
·
c) Insertion sort
·
d) All of these
Answer: d) All of these
19. The time complexity of Bubble sort is —
·
a) O(1)
·
b) O(n)
·
c) O(n²)
·
d) O(log n)
Answer: c) O(n²)
20. Selection sort performs swapping —
·
a) Frequently
·
b) After every comparison
·
c) Once in each pass
·
d) Randomly
Answer: c) Once in each pass
21. Sorting is the process of —
·
a) Finding data
·
b) Arranging data in order
·
c) Copying data
·
d) Deleting data
Answer: b) Arranging data in order
22. Bubble sort repeatedly —
·
a) Divides the list
·
b) Swaps adjacent elements
·
c) Inserts new elements
·
d) Deletes smallest element
Answer: b) Swaps adjacent elements
23. In Bubble sort, total number of passes for n elements is
—
·
a) n
·
b) n-1
·
c) n+1
·
d) n²
Answer: b) n-1
24. The element which 'bubbles up' in Bubble sort is —
·
a) Smallest element
·
b) Largest element
·
c) Middle element
·
d) Random element
Answer: b) Largest element
25. Selection sort finds the —
·
a) Largest element each time
·
b) Smallest element each time
·
c) Middle element
·
d) Random element
Answer: b) Smallest element each time
26. Insertion sort divides the list into —
·
a) Equal halves
·
b) Sorted and unsorted parts
·
c) Random parts
·
d) Two equal halves
Answer: b) Sorted and unsorted parts
27. In Bubble sort, when no swapping occurs in a pass, the
list is —
·
a) Still unsorted
·
b) Completely sorted
·
c) Partially sorted
·
d) Needs another pass
Answer: b) Completely sorted
28. Which of the following has nested loops in its
algorithm?
·
a) Bubble sort
·
b) Selection sort
·
c) Insertion sort
·
d) All of these
Answer: d) All of these
29. The time complexity of Bubble sort is —
·
a) O(1)
·
b) O(n)
·
c) O(n²)
·
d) O(log n)
Answer: c) O(n²)
30. Selection sort performs swapping —
·
a) Frequently
·
b) After every comparison
·
c) Once in each pass
·
d) Randomly
Answer: c) Once in each pass
31. Sorting is the process of —
·
a) Finding data
·
b) Arranging data in order
·
c) Copying data
·
d) Deleting data
Answer: b) Arranging data in order
32. Bubble sort repeatedly —
·
a) Divides the list
·
b) Swaps adjacent elements
·
c) Inserts new elements
·
d) Deletes smallest element
Answer: b) Swaps adjacent elements
33. In Bubble sort, total number of passes for n elements is
—
·
a) n
·
b) n-1
·
c) n+1
·
d) n²
Answer: b) n-1
34. The element which 'bubbles up' in Bubble sort is —
·
a) Smallest element
·
b) Largest element
·
c) Middle element
·
d) Random element
Answer: b) Largest element
35. Selection sort finds the —
·
a) Largest element each time
·
b) Smallest element each time
·
c) Middle element
·
d) Random element
Answer: b) Smallest element each time
36. Insertion sort divides the list into —
·
a) Equal halves
·
b) Sorted and unsorted parts
·
c) Random parts
·
d) Two equal halves
Answer: b) Sorted and unsorted parts
37. In Bubble sort, when no swapping occurs in a pass, the
list is —
·
a) Still unsorted
·
b) Completely sorted
·
c) Partially sorted
·
d) Needs another pass
Answer: b) Completely sorted
38. Which of the following has nested loops in its
algorithm?
·
a) Bubble sort
·
b) Selection sort
·
c) Insertion sort
·
d) All of these
Answer: d) All of these
39. The time complexity of Bubble sort is —
·
a) O(1)
·
b) O(n)
·
c) O(n²)
·
d) O(log n)
Answer: c) O(n²)
40. Selection sort performs swapping —
·
a) Frequently
·
b) After every comparison
·
c) Once in each pass
·
d) Randomly
Answer: c) Once in each pass
41. Sorting is the process of —
·
a) Finding data
·
b) Arranging data in order
·
c) Copying data
·
d) Deleting data
Answer: b) Arranging data in order
42. Bubble sort repeatedly —
·
a) Divides the list
·
b) Swaps adjacent elements
·
c) Inserts new elements
·
d) Deletes smallest element
Answer: b) Swaps adjacent elements
43. In Bubble sort, total number of passes for n elements is
—
·
a) n
·
b) n-1
·
c) n+1
·
d) n²
Answer: b) n-1
44. The element which 'bubbles up' in Bubble sort is —
·
a) Smallest element
·
b) Largest element
·
c) Middle element
·
d) Random element
Answer: b) Largest element
45. Selection sort finds the —
·
a) Largest element each time
·
b) Smallest element each time
·
c) Middle element
·
d) Random element
Answer: b) Smallest element each time
46. Insertion sort divides the list into —
·
a) Equal halves
·
b) Sorted and unsorted parts
·
c) Random parts
·
d) Two equal halves
Answer: b) Sorted and unsorted parts
47. In Bubble sort, when no swapping occurs in a pass, the
list is —
·
a) Still unsorted
·
b) Completely sorted
·
c) Partially sorted
·
d) Needs another pass
Answer: b) Completely sorted
48. Which of the following has nested loops in its
algorithm?
·
a) Bubble sort
·
b) Selection sort
·
c) Insertion sort
·
d) All of these
Answer: d) All of these
49. The time complexity of Bubble sort is —
·
a) O(1)
·
b) O(n)
·
c) O(n²)
·
d) O(log n)
Answer: c) O(n²)
50. Selection sort performs swapping —
·
a) Frequently
·
b) After every comparison
·
c) Once in each pass
·
d) Randomly
Answer: c) Once in each pass
Section B: One Mark Questions
1. Define sorting.
Answer: Sorting is the process of arranging data in a
specific order such as ascending or descending.
2. What is the best case time complexity of Bubble sort?
Answer: O(n) when the list is already sorted.
3. Which sorting algorithm works by repeatedly selecting the
smallest element?
Answer: Selection sort.
4. Which sorting method divides the list into sorted and
unsorted parts?
Answer: Insertion sort.
5. What is a ‘pass’ in sorting?
Answer: A single iteration through the list comparing and/or
swapping elements.
6. In Bubble sort, how many passes are needed for a list of
6 elements?
Answer: 5 passes.
7. Name one application of sorting.
Answer: Sorting helps in searching efficiently or arranging
data systematically.
8. What does swapping mean?
Answer: Exchanging the positions of two elements in a list.
9. What does ‘n’ represent in time complexity?
Answer: The number of elements in the input list.
10. Which sorting algorithm can stop early when no swaps
occur?
Answer: Bubble sort.
Section C: Two Mark Questions
1. Differentiate between Bubble sort and Selection sort.
Answer: Bubble sort repeatedly swaps adjacent elements,
while Selection sort finds the smallest element and swaps it once per pass.
2. State one similarity between Selection and Insertion
sort.
Answer: Both divide the list into sorted and unsorted parts
and move one element per pass.
3. Why is time complexity important in sorting?
Answer: It helps to estimate the efficiency and performance
of an algorithm for large inputs.
4. Explain the term 'nested loop' in sorting algorithms.
Answer: A nested loop is a loop inside another loop, used to
compare multiple pairs of elements.
5. What happens if no swapping occurs during a pass in
Bubble sort?
Answer: It means the list is already sorted and the
algorithm can terminate early.
6. In Selection sort, how many passes are required for n
elements?
Answer: n - 1 passes.
7. Give one advantage of Insertion sort.
Answer: Efficient for small lists or nearly sorted data.
8. Which sorting algorithm performs minimum swaps?
Answer: Selection sort.
9. What is the basic operation in sorting algorithms?
Answer: Comparison between two elements.
10. List two real-life examples where sorting is used.
Answer: Alphabetical arrangement in dictionary and arranging
exam scores in ascending order.
Section D: Three Mark Questions
1. Write an algorithm for Bubble sort.
Answer: Step 1: Repeat passes through the list.
Step 2: Compare adjacent elements.
Step 3: Swap if in wrong order.
Step 4: Repeat until no swaps occur.
2. Describe how Selection sort works with an example.
Answer: Selection sort finds the smallest element and swaps
it with the first element in each pass until the list is sorted.
3. Explain how Insertion sort inserts an element at its
right place.
Answer: It compares the current element with sorted elements
and shifts larger ones right until the correct position is found.
4. Compare Bubble and Insertion sort.
Answer: Both are simple sorting techniques with O(n²) time,
but Insertion sort performs better for nearly sorted lists.
5. What is the time complexity of Bubble, Selection, and Insertion
sort?
Answer: All have time complexity O(n²).
6. Explain why sorting is useful in computing.
Answer: Sorting simplifies searching, data retrieval, and
data analysis.
7. Give a Python statement to swap two elements in a list.
Answer: list[i], list[j] = list[j], list[i]
8. What are the two parts of a list in Insertion sort?
Answer: Sorted part and Unsorted part.
9. What happens to the largest element in each pass of
Bubble sort?
Answer: It ‘bubbles up’ to its correct position at the end.
10. Which sorting algorithm requires least memory space?
Answer: Insertion sort as it works in-place.
Section E: Five Mark Questions
1. Write and explain a Python program for Bubble sort.
Answer: Program:
def bubble_Sort(list1):
n = len(list1)
for i in range(n):
for j in range(0, n-i-1):
if list1[j] > list1[j+1]:
list1[j], list1[j+1] =
list1[j+1], list1[j]
list1 = [8,7,13,1,-9,4]
bubble_Sort(list1)
print(list1)
Explanation: The program compares and swaps adjacent elements until the list is
sorted.
2. Explain Selection sort algorithm and give Python code.
Answer: Algorithm:
1. Repeat for each position in list.
2. Find smallest element in unsorted part.
3. Swap it with the first unsorted element.
Program:
def selection_Sort(list2):
for i in range(len(list2)):
min = i
for j in range(i+1, len(list2)):
if list2[j] < list2[min]:
min = j
list2[i], list2[min] =
list2[min], list2[i]
3. Explain Insertion sort algorithm with example.
Answer: Insertion sort inserts each element into its correct
position in the sorted list.
Example: [8,7,13,1,-9,4] → after sorting → [-9,1,4,7,8,13].
4. Compare Bubble, Selection, and Insertion sort on basis of
working and time complexity.
Answer: All three have O(n²) complexity. Bubble involves
swapping, Selection involves selecting minimum, Insertion involves shifting
elements.
5. Discuss the importance of time complexity in algorithm
selection.
Answer: Time complexity helps in choosing efficient
algorithms suitable for large data sets.
6. Write a program to find the median of a list using Bubble
sort.
Answer: Program sorts the list using Bubble sort and finds
the middle value or average of two middle values if even elements.
7. Explain with example how sorting helps in percentile
calculation.
Answer: Data must be sorted before percentile index is
computed using the formula index = (x/100)*n.
8. Describe how insertion sort can be used for maintaining
ordered student names during admission.
Answer: When a new name is entered, it is inserted at the
correct position, maintaining alphabetical order.
9. Write the algorithm for calculating percentile using
Selection sort.
Answer: 1. Sort data using Selection sort.
2. Calculate index = (x/100)*n.
3. Round off index.
4. Display value at that index.
10. Explain constant, linear, and quadratic time complexity
with examples.
Answer: Constant: O(1) e.g., simple assignment.
Linear: O(n) e.g., single loop.
Quadratic: O(n²) e.g., nested loops in sorting.
.png)
Comments
Post a Comment