Post Reply 
Random Integers, No Repeats
08-09-2023, 05:03 PM
Post: #8
RE: Random Integers, No Repeats
(08-09-2023 03:50 PM)John Keith Wrote:  I would bet that rand uses the Fisher-Yates algorithm internally.

Yes. We need n-1 random numbers, O(n) is as good as we can get.

Conversely, for list x to y, shuffled, number of swaps to restore it is also O(n)
(assume we don't cheat, and just return new list x to y)

We can think of this kind of sort as inverse Fisher-Yates.

Example, Fifteen Puzzle Game Solvability in O(n).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Random Integers, No Repeats - lrdheat - 08-09-2023, 02:30 AM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023, 04:54 AM
RE: Random Integers, No Repeats - Albert Chan - 08-09-2023 05:03 PM
RE: Random Integers, No Repeats - nickapos - 08-09-2023, 04:59 PM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023, 05:10 PM
RE: Random Integers, No Repeats - lrdheat - 08-09-2023, 01:24 PM
RE: Random Integers, No Repeats - Joe Horn - 08-09-2023, 05:31 PM
RE: Random Integers, No Repeats - nickapos - 08-09-2023, 06:04 PM
RE: Random Integers, No Repeats - parisse - 08-09-2023, 06:09 PM



User(s) browsing this thread: 2 Guest(s)