Determining the mode


function mode( S : SetOfKeys ) : SetOfKeys; var A, A1, A2, A3 : SetOfKeys; Homog, Heter : set of SetOfKeys; begin Homog := []; Heter := [S]; while LargestCardinality(Heter) > LargestCardinality(Homog) do begin A := LargestSet( Heter ); med := median( A ); split A into A1, A2, A3 { with elements <med; =med; >med } Heter := ( Heter - A ) + A1 + A3; Homog := Homog + A2 end; LargestSet( Homog ); end;

Pascal source (523.mode.p)



© Addison-Wesley Publishing Co. Inc.