Talk:Selection sort

From Algorithmist
Jump to navigation Jump to search

The pseudocode for this example either has two fencepost errors or uses definitions of "length()" or the "for i from x to y" construct that are different from what is typical.

The code walks through the lst array in two places, both times going to 'max'. The pseudocode implies this is a zero-based array (outer for loop), and max is found from length(lst). If 'for' and 'length' work like most languages, the for loops will walk past the end of the array when they reach 'max'. For the code to work, this pseudocode either defines length() to return 'count of array elements minus one', or the 'for i from x to y' loop construct stops before y (i = y - 1), not at y. Or the code is in error and max needs to be defined as length(lst) - 1.

Fair point -- probably should convert it to Python (and tested!) Larry 15:36, 15 April 2010 (UTC)