Article directory
foreword
提示:提示:本人不喜欢用专业术语来记录知识点,所以接下来会用例题+白话文的方式记录:
Merging sort (Merging Sort) is another sorting method different from insertion sort, exchange sort, and selection sort. Merge means to combine two or more ordered lists into a new ordered list.
提示:以下是本篇文章正文内容,下面案例可供参考
First, merge sort
Thought
The process of merge sort is based on the following basic idea:
"merge" two or more ordered subsequences into one ordered sequence.
In internal sorting, 2-way merge sort is usually used.
It is to merge the ordered subsequences of two adjacent records into an ordered sequence of records.
- Here is a more classic gif from the Internet to show the whole process of merge sort:
method
Consider the records r[0] to r[n-1] to be sorted as n ordered sub-lists of length 1, and merge these sub-lists in turn to get [n/2] ordered sub-lists table, and then merge these [n/2] ordered sub-lists in pairs, and so on, until finally an ordered list of length n is obtained.
example
performance analysis
⑴. Time complexity:
O(nlog 2 n)
⑵. Required auxiliary space:
O(n)
⑶. Algorithm stability:
it is a stable sorting
A total of log 2 n trips are required
Summarize
That is, the two groups are compared as a group, the smaller one is first, the
second time the two groups are compared, the smaller one is first,
and so on .
The final result is ascending order .