OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

Which one of the sorting algorithm given in options will perform sorting of the array 8 9...

Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Which one of the sorting algorithm given in options will perform sorting of the array 8 9 10 2 4 in ascending order?

If the result of 1st pass is = 8 9 2 4 10

If the result of 2nd pass is = 8 2 4 9 10 and so on..

Choose one option.
Show answer & explanation
Answer: B. Bubble sort

Bubble sort compares adjacent elements and swaps them if they're in the wrong order, moving larger elements toward the end with each pass. The given pass results match bubble sort's behavior: Pass 1 bubbles the largest element (10) to the end, Pass 2 bubbles the second-largest (9) to its position. Merge sort uses divide-and-conquer and doesn't produce this sequential single-pass behavior. Heap sort and Quick sort also follow different sorting mechanics that don't match these intermediate states.

Step-by-step Derivation:
Bubble Sort Trace on [8, 9, 10, 2, 4]:

Pass 1 (compare adjacent pairs left to right):

  • Compare 8,9 → no swap: [8, 9, 10, 2, 4]
  • Compare 9,10 → no swap: [8, 9, 10, 2, 4]
  • Compare 10,2 → swap: [8, 9, 2, 10, 4]
  • Compare 10,4 → swap: [8, 9, 2, 4, 10] ✓ Matches given result

Pass 2 (largest is in place, repeat):

  • Compare 8,9 → no swap: [8, 9, 2, 4, 10]
  • Compare 9,2 → swap: [8, 2, 9, 4, 10]
  • Compare 9,4 → swap: [8, 2, 4, 9, 10] ✓ Matches given result

This sequential, single-pass-per-iteration pattern is the hallmark of bubble sort.