Re: Shuffling a linked list



Richard Harter wrote:

.... snip ...

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.

With the extra pointer per node (O(n) space for the extra pointers)
there can be O(n) rand calls, zero data moves.

struct node {
struct node *next, *shuffling;
int used; /* a boolean */ /* probably unneeded */
struct data *datum;
};

struct node *deck, *shuffled;

and the only extra storage needed is for the pointers shuffling.
However the walks using next will be O(n*n). The act of shuffling
up can be combined with the act of dealing, and copying shuffled
into deck when deck becomes empty. With this autoshuffle dealing
need not worry about the deck size remaining (which provides very
nice opportunities for Blackjack players, except that they won't
know when the new deck is used, although they could figure it out
after enough deals).

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>


.



Relevant Pages

  • Re: News: Robertson (need I say more?)
    ... except the will of many within the US is to force religion on ... decks of cards, leave in the two jokers for each deck giving you 540 ... you finished shuffling, was 1. ...
    (talk.origins)
  • Re: News: Robertson (need I say more?)
    ... except the will of many within the US is to force religion on ... decks of cards, leave in the two jokers for each deck giving you 540 ... you finished shuffling, was 1. ...
    (talk.origins)
  • Re: News: Robertson (need I say more?)
    ... except the will of many within the US is to force religion on ... decks of cards, leave in the two jokers for each deck giving you 540 ... you finished shuffling, was 1. ...
    (talk.origins)
  • Re: News: Robertson (need I say more?)
    ... except the will of many within the US is to force religion on ... decks of cards, leave in the two jokers for each deck giving you 540 ... you finished shuffling, was 1. ...
    (talk.origins)
  • Re: Marke Cards/Stacking (LSJ) (rules team)
    ... cards, inside the sleeve, which he would use to "reset" his deck, before ... I don't know about marking cards, but assuming that your shuffling process ... if such a stacking were to create "better ...
    (rec.games.trading-cards.jyhad)