Bubble sorting method of binary search method

Source: Internet
Author: User

Binary search also known as binary search, the advantages are less than the number of comparisons, Find Fast, average performance is good;

The disadvantage is that it requires the unknown origin table to be an ordered table, and insert Delete is difficult. Therefore, the binary lookup method is suitable for an ordered list that does not change frequently and finds frequent.

First, suppose that the elements in the table are sorted in ascending order, comparing the keywords in the middle position of the table with the lookup keywords, and if they are equal, the lookup succeeds;

Otherwise, use intermediate positional records to divide the table into the top and bottom two sub-tables, and if the middle position records a keyword that is larger than the lookup keyword, further finds the previous child table, or further finds the latter one.

Repeat the process until you find a record that satisfies the criteria, make the lookup successful, or until the child table does not exist, the lookup is unsuccessful at this time.

The binary lookup method must follow:

1. Sequential storage structure must be used

2. Must be sorted by keyword size.

Bubble sort

Bubble sort is a simple sort algorithm.

It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order.

The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted.

The name of the algorithm is because the larger the element will slowly "float" to the top of the sequence, hence the name.

The bubbling Sort algorithm works as follows: (from back to forward)

? 1. Compare adjacent elements. If the first one is bigger than the second one, swap them both.

2. Do the same work for each pair of adjacent elements, starting from the first pair to the end of the last pair. At this point, the last element should be the maximum number.

3. Repeat the above steps for all elements except the last one.

4. Repeat the above steps each time for fewer elements until there are no pairs of numbers to compare.

Java Bubble sort

Code:

1  Public classbubblesort{2       Public Static voidMain (string[] args) {3          intScore[] = {67, 69, 75, 87, 89, 90, 99, 100};4           for(inti = 0; i < score.length-1; i++) {//up to do n-1 sort of trip5               for(intj = 0; J < score.length-i-1; J + +) {//sort the current unordered interval score[0......length-i-1]6                  if(Score[j] < Score[j + 1]) {//swap the small value to the back7                      inttemp =Score[j];8SCORE[J] = score[j + 1];9Score[j + 1] =temp;Ten                  } One              }             ASystem.out.print ("First" + (i + 1) + "secondary" results: "); -               for(intA = 0; A < Score.length; a++){ -System.out.print (Score[a] + "\ T"); the              } -System.out.println (""); -          } -System.out.print ("Final sort result:"); +               for(intA = 0; A < Score.length; a++){ -System.out.print (Score[a] + "\ T"); +         } A      } at}
https://zh.m.wikipedia.org/wiki/%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F#. "It was my fq to go out and find Wikipedia material."

Bubble sorting method of binary search method

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.