Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: rand + shift || pop

by JavaFan (Canon)
on Dec 21, 2010 at 16:41 UTC ( [id://878302]=note: print w/replies, xml ) Need Help??


in reply to Re^3: rand + shift || pop
in thread rand + shift || pop

Actually, the expected running time of splicing is Ω(n), as a random splice will have to move n/4 elements on average.

If you want to repeatedly get a random element (without duplication), shuffle the array and use pop or shift, for a linear running time. Repeatedly splicing a random element has an expected running time of Ω(n2).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found