Re: [OT] Linked list fixup [was: Fast DES IP]

From: Kristian Gjøsteen (kristiag+news_at_math.ntnu.no)
Date: 12/09/04


Date: Thu, 9 Dec 2004 12:30:08 +0000 (UTC)

Francois Grieu <fgrieu@francenet.fr> wrote:
>We have a non-empty linked list in RAM, of unknown size n,
>and a pointer to the head node. Instead of nicely ending
>with a node having a NULL "next" field, the list is
>"loopy" and the last node in the list has a "next"
>field that points to some unknown node in the list.
>
>Find an O(n) algorithm using O(1) memory that fixes
>the list, changing the "next" field of the last
>element to NULL.

Funny problem. I can solve it using O(n) time and O(log n) memory.

I think this calls for Pollard's kangaroos. So I go to Australia and
pick up my three favourite kangaroos. Fred is the fast one, Sarah and
Sophie are slow. (What are common kangaroo names?)

I send Fred ahead and ride with Sarah until Fred catches up with us.
Then I send Sarah along and record the time r (here I need O(log n)
memory) until she returns.

Now I return to the starting point. I send Sarah along, and when time
r has elapsed, I ride off with Sophie. When Sarah catches up with me, I
mark the place I'm at (again, O(log n) memory), then ride on with Sophie
until the next jump would bring me to the marked place. This is the end.

Finally, I feed the kangaroos and return them to Australia.

-- 
Kristian Gjøsteen


Relevant Pages

  • Re: [OT] Linked list fixup [was: Fast DES IP]
    ... >>and a pointer to the head node. ... > I think this calls for Pollard's kangaroos. ... > I send Fred ahead and ride with Sarah until Fred catches up with us. ... I ride off with Sophie. ...
    (sci.crypt)
  • Re: [OT] Linked list fixup [was: Fast DES IP]
    ... >> I think this calls for Pollard's kangaroos. ... >> I send Fred ahead and ride with Sarah until Fred catches up with us. ... I ride off with Sophie. ... >problem statement in term of space, for the counter r is O. ...
    (sci.crypt)
  • Re: [OT] Linked list fixup [was: Fast DES IP]
    ... and a pointer to the head node. ... > I think this calls for Pollard's kangaroos. ... > I send Fred ahead and ride with Sarah until Fred catches up with us. ... I ride off with Sophie. ...
    (sci.crypt)
  • Re: [OT] Linked list fixup [was: Fast DES IP]
    ... >> I think this calls for Pollard's kangaroos. ... >As soon as Fred meets sarah, Fred stops and phones Sophie to tell her to start. ... >Sarah continues until she'd bump into Sophie. ...
    (sci.crypt)
  • Re: InDesign "Out of Memory" error
    ... > When I print a document I get an "out of memory" error. ... some file corruption. ...
    (uk.comp.sys.mac)