Re: Shuffling a linked list
- From: cri@xxxxxxxx (Richard Harter)
- Date: Fri, 29 Dec 2006 21:27:18 GMT
On Fri, 29 Dec 2006 20:45:01 +0000 (UTC), Willem <willem@xxxxxxxx>
wrote:
Richard wrote:
) May I refine the challenge as follows: Given a singly linked list of
) length n, randomly shuffle it using O(n) calls to rand, O(n log n) data
) moves, and O(1) extra space.
Assuming that rand() returns at least log n bits of randomness, you can
easily write a wrapper for rand() that returns one bit each time, and calls
the real rand only when it runs out of bits.
That's still a factor of log n.
.
- Follow-Ups:
- Re: Shuffling a linked list
- From: Willem
- Re: Shuffling a linked list
- References:
- Shuffling a linked list
- From: A. Farber
- Re: Shuffling a linked list
- From: Pascal Bourguignon
- Re: Shuffling a linked list
- From: Richard Harter
- Re: Shuffling a linked list
- From: Googmeister
- Re: Shuffling a linked list
- From: Richard Harter
- Re: Shuffling a linked list
- From: Willem
- Shuffling a linked list
- Prev by Date: Re: Hash
- Next by Date: Re: Shuffling a linked list
- Previous by thread: Re: Shuffling a linked list
- Next by thread: Re: Shuffling a linked list
- Index(es):
Relevant Pages
|
|