Discussion
Consider the following array.
| 23 | 32 | 45 | 69 | 72 | 73 | 89 | 97 |
Answer: C
The algorithm with the fewest comparisons is insertion sort.
The array is already in ascending order. Insertion sort compares each new element only with the one before it, finds it already in place, and moves on, so it uses just n - 1 = 7 comparisons.
Selection sort always makes n(n - 1)/2 = 28 comparisons. Merge sort makes about n log n comparisons regardless of order. Quicksort with the last element as pivot hits its worst case on sorted input, also about 28 comparisons.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development