Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

RE (tilly) 2 (one is worse): Re: Randomize an array

by tilly (Archbishop)
on Sep 08, 2000 at 03:23 UTC ( #31514=note: print w/replies, xml ) Need Help??


in reply to Re: Randomize an array
in thread Randomize an array

The one-line should be a good shuffle. However it is O(n log(n)) and Fisher-Yate's is O(n), so the longer code really is better algorithmically.
  • Comment on RE (tilly) 2 (one is worse): Re: Randomize an array

Replies are listed 'Best First'.
RE: RE (tilly) 2 (one is worse): Re: Randomize an array
by Adam (Vicar) on Sep 08, 2000 at 03:34 UTC
    I really should have paid more attention in Algorithm's analysis. Sigh. Maybe I'll take the next level of it when I go back to grad school. You are right. Sort is an implementation of QuickSort ( O(n log n) using lots of memory) while Fisher-Yates is O(n) with a constant defined only by how long it takes to do the rand and the swap. (We had that discussion already. <grin>) So this makes sense. And of course, this defends my suggestion that Fisher-Yates is preferable to the one-liner. Thanks tilly, maybe one day my education will start to sink in.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://31514]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2019-05-20 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (128 votes). Check out past polls.

    Notices?