Discussion
The best/worst case time complexity of Bubble sort is :
Answer: A
Bubble sort is O(n) in the best case and O(\(n^{2}\)) in the worst case.
Bubble sort with the usual 'swapped' flag stops as soon as a pass makes no swaps. On an already sorted array the first pass of n-1 comparisons makes no swaps, so the best case is O(n). On a reverse-sorted array every pass swaps, and about n(n-1)/2 comparisons and swaps are needed, so the worst case is O(\(n^{2}\)).
O(n log n) is the complexity of merge sort and of heap sort, not of bubble sort, which rules out options B, C and D.
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