Visual intuition 7 commonly used sorting algorithms (writing strategies commonly used)

Author: The Little Dream, Created: 2016-12-06 10:23:16, Updated:

7 commonly used sorting algorithms for visual intuition

When writing strategies, it is inevitable to encounter situations in program code that require data sorting, so how do we design scientific programs with the least amount of system overhead (time, system resources)?

  • 1. Quickly sort

    This is the story of my life. Quick sort is a sorting algorithm developed by Tony Hall. In the average case, sorting n items requires n log n comparisons. In the worst case, it requires n2 comparisons, but this is uncommon. In fact, quick sort is often noticeably faster than other log n algorithms because its inner loop can be implemented very efficiently in most architectures, and in most real-world data, design choices can be decided, reducing the likelihood of secondary items taking time. The steps: Select an element from the numbered column, called the pivot, and the pivot is called the pivot. Rearrange the number of columns, with all elements smaller than the reference value placed in front of the reference value, and all elements larger than the reference value placed behind the reference value (the same number can go to either side); after this partition is exited, the reference is in the middle of the number column. This is called the partition operation. Recursive: Sorting sub-arrays of elements smaller than the reference value and larger than the reference value. The ordering effect:img

  • 2. Clustering and sorting

    This is the story of my life. Merge sort is an effective sorting algorithm based on the operation of merging. The algorithm is a very typical application of the divide and conquer method. The steps: Apply a space so that it is the sum of two already ordered sequences that are used to store the merged sequence Set up two pointers, each with the initial position of the start of two sequences that have been sorted Compare the elements pointed to by the two pointers, select the relatively small element to put into the merge space, and move the pointer to the next position Repeat step 3 until a pointer reaches the end of the sequence. Copying all the remaining elements of another sequence directly to the end of the combined sequence The ordering effect:img

  • 3. Stack ordering

    This is the story of my life. Heapsort refers to a sorting algorithm designed to use a data structure such as a heap. A heap is a structure that is almost entirely binary and satisfies the heap property: the key value or index of a sub-node is always less than or greater than its parent node. Step by step: (Complicated, go online and check it yourself) The ordering effect:img

  • 4. Select the order

    This is the story of my life. Selection sort is a simple and intuitive sorting algorithm. It works as follows. First, find the smallest element in the unsorted sequence, store it at the start of the sorted sequence, and then, continue to find the smallest element from the remaining unsorted elements, and then put it at the end of the sorted sequence. And so on, until all elements are sorted out. The ordering effect:img

  • 5. Foam ordering

    This is the story of my life. Bubble Sort is a simple sorting algorithm. It repeatedly visits the array to be sorted, compares two elements at a time, and swaps them if their order is wrong. The job of searching the array is repeated until no more swapping is needed, i.e. the array has been sorted. The steps: Comparing adjacent elements. If the first one is larger than the second one, swap them both. Do the same for each pair of adjacent elements, from the beginning of the first pair to the last pair of the last pair. At this point, the last element should be the largest number. Repeat the above steps for all elements except the last one. Continue to repeat the steps above each time for fewer and fewer elements until no pair of numbers needs to be compared. The ordering effect:img

  • 6. Insert the order

    This is the story of my life. Insertion Sort describes a simple intuitive sorting algorithm. It works by constructing an ordered sequence, scanning unordered data backwards in the ordered sequence, finding the corresponding position and inserting it. Insertion Sort is implemented with in-place sorting (i.e. sorting only the extra space needed to reach O) because it requires repeatedly moving the sorted element backwards in the process of subsequent forward scanning, providing insertion space for the latest element. The steps: Starting with the first element, the element can be considered to have been sorted. Remove the next element and scan it backwards in the sequence of elements that have been sorted If the element ((sorted) is larger than the new element, move the element to the next position Repeat step 3 until you find the position of the sorted element less than or equal to the new element Inserting new elements into the location Repeat step two. The ordering effect: (for now)

  • 7. Hill is sorted

    This is the story of my life. Hill sorting, also known as incremental decomposition sorting algorithm, is a fast and stable improved version of insertion sorting. Hill's method is based on the following two properties of insertion sorting: 1, Insertion sorting is highly efficient when operating on data that is almost already sorted, i.e. it can achieve the efficiency of linear sorting 2, but insert sorting is generally inefficient because insert sorting only moves one data at a timeimg

I'm using the foam method most often (the easiest), and you?


More

Difficult to quantifyI found some JavaScript sorting code. I've been trying to find a way to do this for years.

Difficult to quantifyThank you, Cope.