Solid Foundation-fast sorting

Source: Internet
Author: User

Logical Structure: recursive Stack

Physical Structure: Array


Quick Sort Analysis:

Optimal Time Complexity: O (nlog2n)In disorder

Worst time complexity: O (N ^ 2)In order

Average time complexity: O (nlog2n)

Space complexity: O (N)

Stability: unstable


There are two main functions for quick sorting:

1 indicates int partition (int A [], int low, int high );

2 recursively and quickly sort void quicksort (int A [], int low, int high );

3 Non-recursive quick sorting void nonquicksort (int * a, int low, int high );(Used to solve stack overflow caused by excessive data volume)


 
// Returns the int partition (int A [], int low, int high) of the base whose left side is smaller than the base whose right side is greater than the base value) {int lower = A [low]; while (low  
 // recursively and quickly sort void quicksort (int A [], int low, int high) {int partition; If (low 
   
// Non-recursive fast sorting void nonquicksort (int * a, int low, int high) {int L, H, random; If (low> = high) return; int * s = (int *) malloc (sizeof (INT) * (high-low + 1); int p = 0; partition = partition (A, low, high ); if (low <lower-1) {s [p ++] = low; s [p ++] = lower-1;} If (lower + 1  


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.