Number of comparisons in merge-sort

I studied the topic of merging, in which I came across this concept that the number of comparisons in sorting-sorting (in the worst case and according to Wikipedia ) is (n ⌈lg nβŒ‰ - 2 ⌈lg nβŒ‰ + 1); this is actually between (n lg n - n + 1) and (n lg n + n + O (lg n)). The problem is that I cannot understand what these difficulties are trying to say. I know that O (nlogn) is the complexity of sorting merge, but the number of comparisons?

+4
source share
1 answer

Why compare comparisons

The sorting algorithm has two operations: comparing data and moving data. In many cases, comparison will be more expensive than moving. Think of long lines in a link-based typing system: moving data will simply exchange pointers, but it may require iteration over a large common part of the lines before the first difference is found. Thus, in this sense, comparison may well be a focus operation.

Why is the exact number

: , ( ) , . , , , . , , .

, lg 2. - n , n βŒ‰. , ⌈lg n βŒ‰ , . , , , , ⌈lg n βŒ‰, , . n ⌈lg n βŒ‰ .

m n m + n - 1, , , . , , .. m= n. n - 1 ( ). , n , 2 ⌈lg n βŒ‰ - 1 n ⌈lg n βŒ‰ - 2 ⌈lg n βŒ‰ + 1 .

n 1 , ⌈lg n βŒ‰ , . , . , ⌈lg n βŒ‰, , , n . , , . 2 ⌈lg n βŒ‰ n: , . , n 1.

, Wikipedia:

n ⌈lg n βŒ‰ - 2 ⌈lg n βŒ‰ + 1

. . , , , , license.

, ⌈lg n βŒ‰ = lg n + d 0 ≀ d 1. n (lg n + d) - 2 lg n + d + 1 = n lg n + nd - n 2 d + 1 = n lg n - n (2 d - d) + 1 β‰₯ n lg n - n + 1
, 2 d - d ≀ 1 0 ≀ d 1

, , - n lg n + n + O (lg n) . , n lg n - 0,9 n + 1 . 2 d - d (ln (ln (2)) + 1)/ln (2) β‰ˆ 0,914 d= -ln (ln (2))/ln (2) β‰ˆ 0,529.

, , , - , .


( )

; .

(n lg n - n + 1); (n lg n - n + 1) (n lg n + n + O (lg n))

, , . , , . , , , , .

+7

All Articles