On algorithm and data structure four fast sorting

Source: Internet
Author: User
Tags sort

The previous article introduced a combined ordering of O (NLGN) with time complexity, which describes the same time complexity as O (NLGN) but fast sorting faster than the merge sort (quick sort).

The rapid sequencing is one of the top ten algorithms in the 20th century science and technology field. A sort of classification of Hoare proposed by a. R. in 1960.

Fast sequencing is also a typical application for solving problems with a divide-and-conquer approach. In many programming languages, an array of arrays, an unstable sort of list, uses a quick sort in an internal implementation. And quick sort is often encountered in interviews.

This paper first introduces the idea of fast sequencing, the realization, analysis, optimization and improvement of the algorithm, and finally analyzes the internal implementation of list sorting in. NET.

One principle

The basic idea of a quick sort is as follows:

Randomization of the array.

Take a number out of the series as the middle axis number (pivot).

Put the number larger than this to its right, less than or equal to its number on the left.

Repeat the third step to the left and right intervals until the interval is only one number.

An important step in fast sorting, as shown in the figure above, is to divide the sequence by the number of axes, the left is less than the middle axis number, the right is greater than the number of axes, and then continue this step on the left and right subsequence until the subsequence length is 1.

Here is a breakdown of the steps, the following figure:

The partitioning operation in the above diagram can be divided into the following 5 steps:

Get the Axis element

I scan from left to right, if less than the datum element, then I self increase, otherwise write down a[i]

J Scan from right to left, if greater than datum element, then I self minus, otherwise write down a[j]

Exchange A[i] and A[j]

Repeat this step until I and J are interleaved, then compare to the datum element, and then swap.

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.