One data structures and algorithms

  Binary search

  Selection Sort

  The first element is selected from the data to be sorted in a smallest element, is stored in the starting position of the sequence, and then to find from the remaining unsorted element to the smallest element, is then placed at the end of the sorted sequence. And so on, until all the number of data elements to be sorted is zero.

  Bubble Sort

  1. Comparison of the adjacent elements. If the first than the second large, the two of them exchanged

  2. For each doing the same work for neighbors, from the beginning of the first pair to the end of the last pair. At this point, the last element should be the biggest

  3. Repeat step for all of the elements above, except the last one

  4. Repeat the above steps every time duration of fewer and fewer elements, a pair of numbers until there is no need to compare

  Optimal time complexity: O (n) time cycle no alternative content

  The worst time complexity: O (n ^ 2)

  


  Insertion Sort

  Wuxi Hospital gynecological examination http://www.87554006.com/


  Quick Sort

  By ordering the trip data to be sorted into two separate portions, wherein all of the data part of the data than the other portion to be smaller, then according to this method the two parts are sorted data, the entire sorting process can be recursively

  Shell sort

  The row and column array is inserted in a sorted table, respectively,

  Example: List [11,22,33,44,55,66,77], will be divided into

  11,22,33

  44,55,66

  77

  Comparative 11 and 44, if 44> 11, without exchange, or the exchange, and then 44 and 77 are compared, in Comparative second column. Comparison of the third column. . .

  Merge sort

  Merge sort is a very typical application using divide and conquer method. The idea is to merge sort an array of recursive decomposition, and then merge array.

  After the array into a minimum, and then merge the two ordered array, the basic idea is to compare two arrays front of the number, and who will take the first small who, after taking the corresponding pointer moved back one. Then comparison, an array of empty until the last remaining portion of the copied over to the other array.


Guess you like

Origin blog.51cto.com/14503791/2431283