[Edu-sig] Fwd: Which way did the chicken cross the road?
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Sun, 13 Oct 2002 21:17:05 -0700 (PDT)
On Sun, 13 Oct 2002, Jason Cunliffe wrote:
> > He had been accustomed (over many uses of this problem) to seeing the
> > students end up with some processing upon elements in "increasing"
> > (left-to-right) positional order.
> >
> > He was surprised by a student from Israel, who developed an equally
> > valid solution which swept the array in *decreasing* (right-to-left)
> > positional order.
This reminds me of the electrifying shock I felt when I read through
snippets of code in TAOCP: in almost all of his inner loops, the index
variable decrements from n to 0, rather than from 0 to n. The reason was
that a comparison against zero was slightly faster than a comparison
between arbitrary numbers!
(It doesn't take much to shock me. *grin*)