Summary of basic sorting algorithm

Source: Internet
Author: User
Tags array sort

Basics of basic sorting
  • If a basic sorting algorithm is not more slow than data processing, such as reading and reading, there is no need to find a faster algorithm.
  • If the sorted file fits in memory, the sort method is called an internal sort , and sorting the files from disk is called an external sort . The difference is that an internal sort can easily access any element, but an external sort must sequentially access the element, at least in large chunks.
  • how the ordering program accesses elements : By comparing the keywords, directly accessing the entire element movement;
  • Sort functions have 3 parameters: arrays, left and right borders with sorted word groupsvoid(Item a[], int l, int r);
  • run time of the sorting algorithm: When ordering n elements
    • Select Sort, insert sort, bubble sort, and < Span class= "Mrow" id= "mathjax-span-2" > n 2 proportional;
    • Hill sort (improvement of insertion sort) is proportional to N (3/2);
    • Keyword-index ordering is proportional to N;
  • how to reduce overhead and speed up sorting : (important)
    • Switch to a more efficient algorithm
    • Shorten the internal cycle
    • Check if there is a comparison or swap operation that can be skipped
Basic sorting algorithm type 1. Select sort

Select the smallest element in the array, swap it with the first element in the array, and then find the minor element and swap it with the second element in the array ... Until the entire array sort is complete. That is, by constantly selecting the smallest element in the remaining array to implement.

2. Insert Sort

By constructing an ordered sequence, for unsorted data, a backward-forward scan in a sorted sequence to find the appropriate location to insert. Thus, in the process of backward forward scanning, the ordered elements need to be shifted back and forth gradually, providing the insertion space for the newest elements.

3. Bubble sort

Traverse the file, if the next 2 elements are in the wrong order, swap the two and repeat until the sort is complete

4. Hill sort 5. Index and pointer ordering

Summary of basic sorting algorithm

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.