Discussion
Given a set of n integers the worst case time complexity of quick sort is
Answer: C
The worst case of quick sort is \(\theta(n^{2})\).
The worst case arises when every pivot is the smallest or largest element, for example on already sorted input with the first element as pivot. Each partition then removes only the pivot, and the comparisons add up to \((n-1) + (n-2) + \cdots + 1 = \frac{n(n-1)}{2}\).
\(\theta(n \log n)\) is the average and best case, when partitions are balanced. \(\theta(n)\) is too small for any comparison sort, and \(\theta(n^{2} \log n)\) is larger than quick sort ever needs.
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