![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
Re^4: rand + shift || popby JavaFan (Canon) |
on Dec 21, 2010 at 16:41 UTC ( #878302=note: print w/replies, xml ) | Need Help?? |
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).
In Section
Seekers of Perl Wisdom
|
|