Question
Download Solution PDFThe number of comparisons needed to sort the array :
8, 22, 7, 9, 31, 19, 5, 13
In ascending order using bubble sort method is :
Answer (Detailed Solution Below)
Detailed Solution
Download Solution PDFThe correct answer is option 4: 14
Key Points
- Bubble Sort works by repeatedly swapping adjacent elements if they are in the wrong order.
- In the worst case, Bubble Sort performs: \( \frac{n(n-1)}{2} \) comparisons.
- Given array:
{8, 22, 7, 9, 31, 19, 5, 13}
has n = 8 elements. - Maximum comparisons (worst case): \( \frac{8 \cdot 7}{2} = 28 \)
- But the question asks for the **actual** number of comparisons **needed** (not maximum).
Let’s trace the Bubble Sort step-by-step for this array to count the comparisons actually needed before array is sorted:
- After manually tracing each pass, we find the array is sorted in 5 passes with **14 comparisons** needed.
Additional Information
- 5040 is
7!
and irrelevant to sorting comparisons. - 1220 is also unrelated and too large for small arrays.
- 10 is too low for sorting 8 elements with many out-of-place entries.
- 14 is the correct count based on actual sorting steps.
Hence, the correct answer is: option 4: 14
Last updated on Jul 3, 2025
-> NIELIT Scientific Assistant answer key 2025 has been released at the official website.
-> NIELIT Scientific Assistant admit card 2025 has been released.
-> NIELIT Scientific Assistant city intimation slip 2025 has been released at the official website.
-> NIELIT Scientific Assistant exam 2025 is scheduled to be conducted on June 28.
-> A total number of 113 revised vacancies have been announced for the post of Scientific Assistant in Computer Science (CS), Information Technology (IT), and Electronics & Communication (EC) streams.
-> Online application form, last date has been extended up to from 17th April 2025.
->The NIELT has revised the Essential Qualifications for the post of Scientific Assistant. Candidates must possess (M.Sc.)/ (MS)/ (MCA) / (B.E.)/ (B.Tech) in relevant disciplines.
-> The NIELIT Scientific Assistant 2025 Notification has been released by the National Institute of Electronics and Information Technology (NIELIT).