Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ptsfa!pacbell!att-ih!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!uxc.cso.uiuc.edu!uicsrd.csrd.uiuc.edu!jaxon From: jaxon@uicsrd.csrd.uiuc.edu Newsgroups: comp.lang.apl Subject: Re: MODE Message-ID: <49700001@uicsrd.csrd.uiuc.edu> Date: 29 Feb 88 17:20:00 GMT References: <1428@water.waterloo.edu> Lines: 28 Nf-ID: #R:water.waterloo.edu:1428:uicsrd.csrd.uiuc.edu:49700001:000:810 Nf-From: uicsrd.csrd.uiuc.edu!jaxon Feb 29 11:20:00 1988 For a large array, the outer product in the above solution can be slow. A solution that makes fewer comparisons is: $ MODE is MODE V;#CT;FREQ;NUB;T [1] #CT is 0 note Need transitivity of = [2] V is V[gradeup V] [3] NUB is 1,(1 drop V) neq (^1 drop V) [4] FREQ is T - ^1 drop 0,T is NUB/iota rho T [5] MODE is (FREQ=max/FREQ)/NUB/V [6] MODE is MODE[floor .5 times ''rho rho MODE] $ After obtaining the FREQuency counts in line 4 you might wish to select the MODE a different way, Line[5] selects all of them. Iverson's Window Reduction operator could be used on lines [3] and [4]. Since gradeup is o(n log n) this algorithm is faster in the limit cases, but probably won't beat Prof. Dickey over short vectors. P.S. $ = del, ^ = high minus, # = quad. Greg Jaxon (jaxon@uicsrd.uiuc.edu)