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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).