Select Sorting Algorithm and Sorting Algorithm

Source: Internet
Author: User

Select Sorting Algorithm and Sorting Algorithm

The idea of selecting a sorting algorithm is similar to Bubble sorting. the maximum or minimum values are selected from the sequence that is not sorted each time, and placed in the header or tail of the array. However, the algorithm is not compared to the bubble algorithm, but an unordered array in each loop. It finds the index of the maximum or minimum value and exchanges it with the header or tail of the unordered array. The sorting ends when only one unordered array is left. Java code implementation is as follows:

Public static void SelectionSort (int [] array) {for (int I = 0; I <array. length; I ++) {int min = array [I]; int key = I; for (int j = I + 1; j <array. length; j ++) {if (min> array [j]) {min = array [j]; key = j ;}} int temp = array [I]; array [I] = min; array [key] = temp ;}}

Select the time complexity of sorting as O (n ^ 2) and space complexity as O (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.