in reply to Re^3: rand + shift || pop
in thread rand + shift || pop
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).
|
|---|