while finding the next value as in the following pseudocode (arrays are zero-based and the for-loop includes both the top and bottom limits, as in Pascal): bingo(array A) { This procedure sorts in ascending order by repeatedly moving maximal items to the end. } begin last := length(A) - 1; { The first iteration is written to look very similar to the subsequent ones, but without swaps. } nextMax := A[last]; for i := last - 1 downto 0 do if A[i] > nextMax then nextMax := A[i]; while (last > 0) and (A[last] = nextMax) do last := last - 1; while last > 0 do begin prevMax := nextMax; nextMax := A[last]; for i := last - 1 downto 0 do if A[i] > nextMax then if A[i] <> prevMax then nextMax := A[i]; else begin swap(A[i], A[last]); last := last - 1; end while (last > 0) and (A[last] = nextMax) do last := last - 1; end; end; Thus, if on average there are more than two items with the same value, bingo sort can be expected to be faster because it executes the inner loop fewer times than selection sort. See also Selection algorithm References Donald Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching, Third Edition. Addison–Wesley, 1997. . Pages 138–141 of Section 5.2.3: Sorting by Selection. Anany Levitin. Introduction to the Design & Analysis of Algorithms, 2nd Edition. . Section 3.1: Selection Sort, pp 98–100. Robert Sedgewick. Algorithms in C++, Parts 1–4: Fundamentals, Data Structure, Sorting, Searching: Fundamentals, Data Structures, Sorting, Searching Pts. 1–4, Second Edition. Addison–Wesley Longman, 1998. . Pages 273–274 External links – graphical demonstration Sorting algorithms Comparison sorts Articles with example C code