In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you how to achieve rapid sorting in web development, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
quick sort
Quick sort is a sort algorithm developed by Tony Hall. On average, sorting n items takes O (nlogn) comparisons. In the worst case, O (n2) comparisons are required, but this is not common. In fact, quicksort is often significantly faster than other ○ (nlogn) algorithms because its inner loop can be implemented efficiently on most architectures.
Quicksort uses a Divide and conquer strategy to divide a list into two sub-lists.
Quick sort is also a typical application of divide-and-conquer idea in sorting algorithm. In essence, Quick Sort is a recursive divide and conquer method based on Bubble Sort.
algorithm steps
Select an element from the sequence, called a "pivot"(pivot);
Reorder the sequence so that all elements smaller than the reference are placed in front of the reference and all elements larger than the reference are placed behind the reference (the same number can be placed on either side). After this partition exits, the datum is in the middle of the series. This is called the partition operation;
recursively sorting the subsequence of elements smaller than the reference value and the subsequence of elements larger than the reference value;
The bottommost case of recursion is when the size of the sequence is zero or one, which means that it has always been sorted. Although recursion continues, the algorithm always exits, because in each iteration it moves at least one element to its final position.
Source: github.com/hustcc/JS-Sorting-Algorithm
algorithm demo
Sort animation process explanation
First, manipulate all the numbers in the sequence.
Choose a number among all the numbers as the sorting basis (pivot), pivot is usually randomly selected, here for demonstration convenience, we choose the rightmost number as the pivot
After selecting the pivot, select the leftmost number in the operation sequence as the left mark, and the rightmost number as the right mark.
Move the left marker to the right
Stop moving when the left marker reaches a number that exceeds pivot
Here, 8 > 6 , so stop moving
Then move the marker on the right to the left.
Stop moving when the right marker reaches a number less than pivot
Here, 4.
< 6 ,所以停止移动 当左右标记停止时,更改标记的数字 因此,左标记 的作用是找到一个大于 pivot 的数字,右标记 的作用是找到一个小于 pivot 的数字 通过交换数字,可以在数列的左边收集小于 pivot 的数字集合,右边收集大于 pivot 的数字集合 交换之后,继续移动 左标记 在这里,9 >6 , so stop moving
Then move the marker on the right to the left.
Also stops moving when right marker collides with left marker
If the left and right markers stop and are both in the same position, swap this number with the pivot number
That completes the first operation.
Anything less than 6 is to the left of 6, and anything greater than 6 is to the right of 6.
Then recursively do the same thing for both parts of this split.
Complete Quick Sort
code implementation
In order to better let readers understand animation with their familiar programming language, the author will post a variety of programming language reference code, code all from the Internet.
C++ code implementation
Java code implementation
Python code implementation
JavaScript code implementation
The above is "how to achieve rapid sorting in web development" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.