First, select the sort
Concept Understanding:In an array of length 3, 3 data is traversed on the first pass to find the smallest value exchanged with the first element ;The second pass traverses 2 data to find the smallest element and the first number Exchange (note: The first number here refers to the first number of the traversal, which is essentially the second number of the array)And the third trip is to compare with yourself, position or
Classic sort: bubble sort + Select sortExample Fjutoj 1842Bubble sortThe principle is to take the next two numbers to compare the size, determine whether the exchange.In order from small to large for example, bubble sort like bubbles, the smallest number slowly floating up,
Monologue: First Contact algorithm sequencing, full of curiosity and eager to understand the principles, today we first learned three kinds of sorting methods, namely bubble sort, select sort, insert sort. After learning that math knowledge is really important, the more good algorithm requires more knowledge, more ref
Bubble Sort:Thought: bubbling sort repeatedly visited the sequence to sort, comparing two elements at a time, swapping them out if they were in the wrong order. The work of the sequence of visits is repeated until no more exchange is needed, that is, the sort is complete.Features: Relatively stable, the number of smal
the address, take this value in turn to compare, when the value is found smaller than it, change the address in the Indexleast, replaced by a small address number, It is then exchanged with the address of the numeric value that is compared, and after the exchange, it continues to be compared with the value in the Indexleast address.template Bubble Sort:To sort a sequence with n elements in ascending order
Last said bubble sort left 2 questions, one is the selection sort, one is the bubble sort performance, this time will say select sort first, then say bubble
Experiment Six: SortOriginal page Link: Your current location: Home > Course ExperimentExperimental project name: sortexperimental purposes and requirements:1. Familiar with the characteristics of commonly used sorting methods. 2. Apply sorting methods to solve specific problems.experimental Principles and illustrations: 1. The sequence (13,6,3,31,9,27,5,11) is inserted directly into the ordering process as follows:Initial: "13", 6, 3, 31, 9, 27, 5, 111th trip: "6, 13", 3, 31, 9, 27, 5, 112nd tr
Bubble Sort:Consider the elements to be sorted as "bubbles" that are vertically arranged, smaller elements lighter and thus upward#!/bin/env python#_*_ coding:utf-8 _*_# algorithm bubble sort li = [13,22,6,99,11]for m in range (Len (LI)-1): if LI[M] > li[m+1]: temp = li[m] li[m] = li[m+1] li[m+1] = temp# for the first time # 13>22->pass# the second time # 22>6->l
= array[x];ARRAY[X] = Array[y];Array[y] = temp;}Second, choose the sort1, principle: Select a value array[0] as a benchmark, and then loop to find the smallest value except this value (find the minimum value less than the benchmark), exchange these two values, then the minimum value is placed on the array[0], and then the array[1] as a benchmark, from the remaining unsorted value found in the minimum value, And swap the two values.(graphs in data structures and algorithms)2. Time complexity: O
Public classMysort {/*** Insert sort (small to large) * @param arr* @return */ Public int[]Insertsort(int[] arr) { for(inti =1; I length; i++) {intCopynum = arr[I];intTargetindex = i;/** copynumindex>0 See if this copynumindex is out of bounds now.* Copynum* are satisfied, it proves that no location has been found for insertion */ while(targetindex>0 copynum1]) {arr[Targetindex] = arr[Targetindex-1];//Let the previo
I. Bubble Sorting
Compare two adjacent numbers in sequence, place decimal places in front, and place large numbers in the back. That is, first compare the numbers of 1st and 2nd, and put the decimal places before and after the large numbers. Then compare the numbers of 2nd and 3rd, place the decimal places before and after the large number, and continue until the last two digits are compared. Place the decimal places before and after the large numbe
Exchange sort(1) Bubble sort1, the basic idea: in order to sort a group of numbers, the current is not yet ranked in the range of all the number, top-down to the adjacent two numbers in turn to compare and adjust, so that the larger number to sink, smaller to the top. That is, each time a comparison of two adjacent numbers finds that they are in the opposite orde
------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------Yesterday to do the basic test questions, encountered a sort of problem, after writing the brain suddenly jumped out of the "bubble sort method" of the term. "Bubble sorting" and "choice of sorting" is a b
Exchange sortThe so-called exchange, which is based on the comparison of the two record key values in the sequence of the position of the two records in the sequence, the characteristics of the Exchange order is: A record of large key values to the end of the sequence of movement, the key value of a small record to the front of the sequence movement.Sort by bubble sort of getting StartedBubble
1 defInsertsort (A):2' Insert sort algorithm: Pass in a list, sort the numbers in list '3 Print(' Insert sort before list element order: ', A)4Length=len (A)5For I in Range (1,length): #从第二个开始6Key=a[i]7J=i-18While J>=0 and A[j]>key:9A[J+1]=A[J]TenJ=j-1 OneA[j+1]=key A Print(' Insert sorted list element order: ', A) -#插入排序时间复杂度: n^2, Spatial complexity: 1, same el
Select and Bubble
#include
NBSP Quick Sort vs. bubbling, selecting comparison:
#include
1. Quick Sort Results:99,999 random numbers in general no more than 0.05 seconds, soon2. Sorting results by Selection method:
99,999 random numbers in general no more than 0.05 seconds, soon2. Sorting results by Selection method:
Generall
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.