Flooding Is A Powerful Abstraction
Consider the mode of a set of numbers
most := 0; count := 0;
for i := 1 to n do
[i] trial := +<<S; --Select ith elem
count := +<<(S = trial); --Occurrences
if count > most then --Have a winner?
most := count; -- Yes remember it
mode := trial; -- And save mode
end;
end;
Is this a high performance solution?
Embellishment ...
- Don’t go to end: for i := 1 to n-count do
What about the reduction?