Algorithm 2 Place Selection Sort Second Algorithm Place Selection Sort Described Figure 53 Q37060575

Algorithm 2: in-place selection sort

The second algorithm is in-place selection sort, as described infigure 5.3 on page 124 of ADITA 0.9.10. This code will be longer,but can be a direct translation of the pseudocode in figure 5.3into C++ code.

Selection sort takes O(n2)time, but it is very simple and avoidsexpensive operations such as memory allocation, recursion, andgenerating random numbers. Therefore we expect it to have the bestconstant factors of all four algorithms. Hypothesis 1 suggests thatselection sort will be fastest for very small n, perhaps n100.However our theory predicts that the other O(n n)-timealgorithms will be faster for large n.

Implement it

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.