Algorithm and data structure-sorting (I) Overview

Source: Internet
Author: User

I recently studied the book "big talk Data Structure". I used to think that I understood it and thought I understood it. In fact, it is not. When I really want to close the book and write it on my own, I found that I still don't know, so in this learning process, in order to achieve better results, every time I understand a certainAlgorithmThen close the book, implement it by yourself, and summarize the ideas of each algorithm in your own words. To deepen my understanding, the next series will be my notes when I am studying the book "big talk Data Structure. The reason for recording this is to deepen my own impression, and to make myself a good habit of summing up. Because the content is some notes learned by myself, there are many examples in the book "big talk Data Structure", please don't be surprised. In addition, some other content is my personal understanding. If there are any errors, please criticize and correct them.

In addition, the book "big talk Data Structure" is indeed good. We strongly recommend it !!!

All right, let's talk less, and let's get started. We need to understand some concepts before we officially study sorting. We don't need to explain the sorting. Everyone understands it. There are two types of sorting: stable sorting and unstable sorting. What is stable sorting? Generally, sorting can be performed based on different keywords. For example, according to the keyword A, Michael Jacob is ranked before the keyword B, zhang San and Li Si are the same. At this time, if the final result is that Michael is at the top of the list, then there is a stable sorting. If Michael is at the end of the list and Mr. Li is at the top of the list, it is unstable. In another specific example, if my total score in the class is ranked before you, even if our four-level score is the same, I am still ahead of you in the final ranking, this is called stable sorting, otherwise it is unstable.

Sorting can be divided into inner sorting and external sorting by another method. When data is relatively small, the numbers are loaded into the memory for sorting in the memory. External sorting means that a large amount of data can be sorted by loading only a part of data into the memory each time. After the sorting is completed, a part of data can be loaded from the external storage. It requires multiple exchanges between the internal and external storage.

Later I will introduce some inner sorting algorithms.

For inner sorting, there are three key factors that affect the algorithm performance: time, space, and complexity.

Time: for sorting algorithms, time overhead is an important factor in measuring the quality of sorting algorithms. Generally, sorting involves comparing and moving operations. The comparison is to compare the size of two numbers. Moving is to switch the positions of two numbers. Efficient Algorithms should have a small number of comparisons and a small number of moves.

Space: The space here refers to the auxiliary space. That is, the space required in addition to the quantity to be sorted. These spaces can be used in sorting, and sometimes space can be used to reduce time consumption. They can be converted to each other, so space is also an important factor in measuring the quality of algorithms.

Complexity of the algorithm itself: This is from the perspective of the algorithm itself. It depends on the unreasonable combination of your algorithm design and the complexity of your ideas.

The above is something you should know before learning the sorting algorithm. Next, I will implement several common algorithms in sequence. The entire series of learning will introduce eight algorithms: Bubble, selection, insert, Hill, merge, heap sorting, fast sorting, and base sorting.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.