iOS common algorithm (dichotomy bubble select Fast row)

Source: Internet
Author: User

Dichotomy: Average time complexity: O (log2n) int halffuntion (int a[], int length, int number) {int start = 0;int End = Length-1;int index = 0;whi Le (Start < end) {index = start + (end-start)/2if (a[index] = = number) {return index;} else if (A[index] < number) {St Art = index + 1; } else{end = Index-1;}} return index; } Bubble Sort:

/**

Average time complexity: O (n2)

Space complexity: O (1) (for Exchange)

Stability: Stable

*/

void paofuntion (int a[], int length) {

for (int i = 0; i < length-1; i++) {

for (int j = 0; J < length-1-I; j + +) {

if (A[j] > a[j+1]) {

int temp = A[j];

A[J] = a[j+1];

A[J+1] = temp;

}

}

}

}

Select Sort:

/**

Average time complexity: O (n2)

Spatial complexity: O (1) (for Exchange and record indexing)

Stability: Unstable (such as sequence "5, 5, 3" The first trip will be the first [5] with [3], causing the first 5 to move to the second 5 back)

*/

void choosefuntion (int a[],int length) {

for (int i = 0; i < length-1; i++) {

for (int j = i + 1; j < length; J + +) {

if (A[i] > A[j]) {

int temp = A[j];

A[J] = A[i];

A[i] = temp;

}

}

}

}

Quick line: Click to open link

http://blog.csdn.net/niejiafa_131/article/details/44807653

iOS common algorithm (dichotomy bubble select Fast row)

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.