Commonly used sorting algorithms: quick sort, merge sort and heap sort

I. References

1.1 Importance of sorting

Sorting is a basic concept in computer science. Whether it is database query, or web page sorting of search engines, or even sorting of to-do items in daily life, they are inseparable from sorting. The purpose of sorting is to arrange a set of unordered data into an ordered sequence according to certain rules (such as size, priority, etc.), so that we can process and use data more effectively.

1.2 Evaluation index of sorting algorithm

To evaluate the quality of a sorting algorithm, we usually consider the following indicators: time complexity, space complexity, stability, and in-place. Time complexity indicates the running speed of the sorting algorithm, space complexity indicates the extra space that the sorting algorithm needs to occupy, stability indicates whether the same elements can maintain the original relative order after sorting, and in-place indicates whether the sorting algorithm only needs a constant level additional space.

1.3 Introduce the three sorting algorithms that will be discussed in this article: quick sort, merge sort and heap sort

This article will detail three commonly used sorting algorithms: quick sort, merge sort, and heap sort. These three sorting algorithms are comparison sorting, that is, sorting is performed by comparing the size of elements. Quick sort is a sorting algorithm based on a divide-and-conquer strategy, and merge sort is also based on a divide-and-conquer strategy, but it achieves sorting by merging two sorted sequences, while heap sorting is by building a heap (a special Binary tree) to implement sorting. Each of these three sorting algorithms has advantages and disadvantages, which we will describe in detail in later chapters.

II. Quick Sort

2.1 How Quick Sort works

Quicksort is an efficient sorting algorithm that works by selecting an element (called a "pivot" or "pivot") as a benchmark, then comparing other elements with the benchmark, and placing elements smaller than the benchmark in the To the left of the datum, elements larger than the datum are placed on the right of the datum, this process is called

Guess you like

Origin blog.csdn.net/a871923942/article/details/130667949