Discussion
What is the worst-case time complexity of insertion sort ?
Answer: C
The worst-case time of insertion sort is \(O(n^{2})\).
In the worst case, a reverse-sorted array, the i-th element has to be shifted past all i - 1 elements before it:
\[ 1 + 2 + \cdots + (n-1) = \frac{n(n-1)}{2} \]
That number of comparisons and shifts grows as n squared.
O(n) is insertion sort's best case, on input that is already sorted. O(n log n) is the bound for merge sort or heapsort, and O(log n) is a single binary search, not a full sort.
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