Can someone clarify the difference between Quicksort and Randomized Quicksort?

How does this differ if I select a randomized bar and just select the first bar in an unordered set / list?

If the set is disordered, the first value in the set is not selected, by itself? Essentially, I'm trying to figure out how / if randomization promises is the best worst-case execution time.

+4
source share
1 answer

I think you can mix the concepts of arbitrary and random. Arbitrary to choose the first element of the array - you could choose any element that you would like, and it will work equally well, but this is not accidental. A random choice is one that cannot be predicted in advance. An arbitrary choice is one that can be.

Imagine using quicksort in a sorted sequence of 1, 2, 3, 4, 5, 6, ..., n. If you select the first element as a bar, then you select 1 as the fulcrum. All n - 1 other elements then go right and nothing goes left, and you will sort 2, 3, 4, 5, ..., n recursively quickly.

, 2 . , 3, 4, 5, 6,..., n , 3, 4, 5, 6,..., n.

, , , + 1, + 2,..., , .

, , , (n 2), ( 2, 3,..., n 1) n-1, ( 3, 4, 5,..., n 2) n-2 .. , (n-1 ) + (n-2) +... +1 = & Theta; (n 2), !

. . , , , , ( 2 2 - n ), . , , , , , , .

quicksort , , & Theta; (n log n), , O (n log n). , (1) O (n log n), , (2) O (n 2), , , .

+4

Source: https://habr.com/ru/post/1666046/


All Articles