STL __merge_without_buffer?

Where can I get a decent high-level description of the algorithm used in __merge_without_buffer()the C ++ STL? I am trying to redefine this code in the D programming language with some improvements. I can’t understand what it does at the algorithmic level, just by reading the STL source code, because too many low-level details hide it. In addition, I do not want to just blindly translate the code, because if it didn’t work, I would not know why, and I could not add my improvements.

+3
source share
1 answer

__merge_without_buffer()performs a merge in place , like the merge step of a merge merge in place. As input, you need to enter two ranges of data [first, middle)and [middle, last), which, as expected, will already be sorted. The parameters len1and len2are equal to the lengths of the two input ranges, namely (middle - first), (last - middle)respectively.

. A1 B1 A2 B2, A1 - [first, middle), , , A2 - [first, middle) B1 [middle, last) , , B2 - [middle, last), . , A1 A2 B1 B2, , , A2 B1 B1 A2. std::rotate(), .

, , (A1 B1), , pivot (A2 B2), A1 A2 B1 B2.

? , , (.. [first, middle) , [middle, last), [first, middle), [middle, last)). , . , 3/4 , 1/4 , .

? std::rotate() O (N), . O (N log N). , mergesort: , mergesort , . , mergesort :

T(N) = 2T(N/2) + O(N log N)

-, , mergesort O (N log 2 N ) !

:

  • O (N log N)

2 - quicksort (1) (3), mergesort (2) (3), (1) (2). , , , 3, . , , 3, , , .

+11

All Articles