Sort

Heap sort, with spatial in-situ: only a constant number of additional element space is needed to store temporary data at any time.
How to reflect the original location of space? (Question one)

A method of using the same storage unit to store calculation input and output data.


Application scenario selection sorting algorithm:
excerpted from http://blog.csdn.net/mbuger/article/details/67643185
(1) If n is small (for example, n≤50), direct insertion or direct selection sorting can be used.
 When the record size is small, direct insertion sorting is better; otherwise, because the number of records moved by direct selection is less than that of direct insertion, direct selection sorting is appropriate.
(2) If the initial state of the file is basically in order (referring to the positive order), it is appropriate to use direct insertion, bubbling or random quick sorting;
(3) If n is large, the time complexity of O(nlgn) should be used. ): quicksort, heapsort, or mergesort.
 Quick sort is currently considered to be the best method in internal sorting based on comparison. When the keys to be sorted are randomly distributed, the average time of quick sort is the shortest;
 heap sort requires less auxiliary space than quick sort, and does not The worst case possible for quicksort occurs. Both sorts are unstable.
 If sorting is required to be stable, merge sort can be used. However, the above-mentioned sorting algorithm for pairwise merging from a single record is not worth advocating, and
  it can usually be used in combination with direct insertion sort. First use direct insertion sort to obtain longer ordered subsequences, and then merge them in pairs.

  Because direct insertion sort is stable, the improved merge sort is still stable.


My purpose of learning algorithms is to exercise mathematical thinking for the time being, to use the thinking of programs to understand and solve problems. I haven't reached the level of writing algorithms for the time being, so the temporary learning depth is to understand what kind of scenarios to use.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325742554&siteId=291194637