Yes, that's the cost. The trick is to avoid initializing count altogether, because for this subproblem M is much greater than n. The answer is algorithmic and not a matter of using this or that C operation.
Recently I had occasion to use the trick for M=65536 and n about 5000. As originally posed, I think the intention was that M would be zillions. On Thu, Mar 6, 2014 at 12:59 PM, Joe Bogner <joebog...@gmail.com> wrote: > On Thu, Mar 6, 2014 at 3:48 PM, Roger Hui <rogerhui.can...@gmail.com> > wrote: > >> Suppose M is really large and the cost of setting count to 0 is > > prohibitive. How can you avoid that cost? > >> (Not saying it's related to finding the min or the max). > > To clarify, do you mean how can you avoid the cost of this operation? > > memset(b,0x00,sizeof(b)); > > In my example I was using: > > for (; j < 32767; j++) { > count[j] = 0; > } > > Is this the cost you are referring to? > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm