Discussion
Which sorting algorithm has worst-case time complexity of O(n2) ?
Answer: B
The algorithm with worst-case time O(n2) is Quick Sort.
Quick sort is O(n log n) on average, but if the pivot chosen is always the smallest or largest element (for example, taking the first element of an already sorted array), each partition removes only one element and the work grows as n + (n - 1) + ... + 1, which is O(n2).
Merge sort and heap sort are O(n log n) even in the worst case. Counting sort is not a comparison sort and runs in O(n + k), where k is the range of the keys.
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