Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python shuffle algorithm performance

I was wondering about the time complexity of the shuffle function in the random Python library/module. Is it O(n) or is it less than that?

Is there a website that shows the time complexities of functions that belong to Python libraries?

like image 431
Saher Ahwal Avatar asked Feb 21 '12 01:02

Saher Ahwal


1 Answers

You cannot shuffle a list in a completely random fashion in less than O(n).

The implementation of random.shuffle() uses the Fisher-Yates shuffle algorithm, which is easily seen to be O(n).

like image 131
Sven Marnach Avatar answered Sep 28 '22 19:09

Sven Marnach