+ 2

Why does swap function from stl when used in selection sort increases the execution time from 19900 ns to 2 ,3 times much?

5th Oct 2020, 11:53 AM
Abhay
Abhay - avatar
2 odpowiedzi
+ 1
My best guess is because std::swap introduces a time overhead of two function calls,std::swap itself and std::move. Considering that the swapping step of the selection sort algorithm runs in O(n^2) in the worst case scenario,then it's easy to see why that small overhead quickly grows into some noticeable delay.
6th Oct 2020, 6:08 AM
Anthony Maina
Anthony Maina - avatar
+ 1
Anthony Maina makes sense ,thank you :)
6th Oct 2020, 8:00 AM
Abhay
Abhay - avatar