Discussion
The number of times swap function called for the selection sort on an array with N numbers is :
Answer: D
Selection sort calls swap N-1 times.
Selection sort makes N-1 passes. In each pass it scans the unsorted part to find the smallest element and then swaps it into the first unsorted position, one swap per pass. After N-1 passes the last element is automatically in place. (An implementation that skips swapping an element with itself can do fewer, but the standard count is N-1.)
\(N^{2}\) is the order of the number of comparisons, about N(N-1)/2, not swaps. N log N is the cost of efficient sorts such as merge sort, and log N is far too few to move N elements into place.
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