@vn-ml.bsky.socialClément Canonne @ccanonne.github.io
2024-12-14 10:50 UTC
This is such a beautiful algorithm (and a nice analysis): to check if an array is sorted vs. far from being sorted (many entries need to be changed), just: - pick an element uniformly at random in the array - "forget" where it was - try to find it again via binary search Repeat this a few times.
Quoting @ccanonne.github.io: <spoiler> The analysis is not obvious, but yes, that's the idea! * Repeat O(1) times: - Pick an index i uniformly at random, let x←A[i] - Do a binary search for x in A, end at index j - Return UNSORTED if i≠j * Return SORTED </spoiler>
28 likes, 5 reposts, 0 replies
3 Next post4 More from @ccanonne.github.ioBackBluesky home