CSDN check-in activity
output
Event address: CSDN 21-day learning challenge
The biggest reason for learning is to get rid of mediocrity. One day earlier, there will be more splendor in life; Dear friends, if you:
want to systematically/deeply learn a certain technical knowledge point...
it is difficult to persist in learning alone, and want to learn efficiently in a group...
want to write a blog but can't start, and urgently need to inject energy into writing dry goods...
love writing, willing to let yourself become better people
...
creative plan
**
chance
Experience sharing in actual combat projects
Records in the daily learning process
Technical exchanges through articles
...
reward
Hope to make like-minded friends
Improve the basic level of personal algorithm
...
daily
Produce 2-3 articles per week on average
With limited energy, I can only spend less time playing games, and I dare not spend less time with my girlfriend
look forward to
Looking forward to tens of thousands of fans and millions of views! !
**
study plan
**
learning objectives
Always full of enthusiasm, stick to 21 days of learning and clocking in
Learning Content
quick sort
study diary
**
Learning knowledge points
Introduction to Bubble Sort
Bubble sort, also known as bubble sort, is a classic exchange sort method. The whole process is to compare adjacent elements in pairs in the unordered area, exchange a pair of elements that do not satisfy the relative order, and then compare the next pair of elements. After each bubbling trip, a smallest element will be sent to the top. Repeat this process in the unordered region until all elements are in order.
quick sortQuick sort is an improved algorithm of bubble sort. The main idea is to take an element (usually the first) in the sequence to be sorted as a reference, and divide the sequence into two subsequences, elements smaller than the reference value and elements larger than the reference value The elements of each form a subsequence. Each pass sorts the reference element and results in two subsequences. Continue this step in the subsequence until the length of the subsequence is 0 or 1.
Algorithm description
Quick sort is a partition exchange sorting method that uses a divide-and-conquer strategy. First, the original problem is divided into several smaller-scale sub-problems similar to the original problem, and then these sub-problems are solved by recursive methods, and finally they are combined into the solution of the original problem.
Arrange a number in the sequence in the first pass, put it where it should be, and get two subsequences at the same time, the numbers on the left are smaller than it, and the numbers on the right are larger than it (in ascending order) . Next, repeat the process of homing an element in each subsequence and obtaining the subsequence until the length of the subsequence is 1 or 0, and the overall sequence is already in order.the complexity
Space complexity : logn
is mainly due to the use of stack space caused by recursion.
In the best case, the depth of the tree is: log2(n)
space complexity is O(logn)
and in the worst case: n-1 is required calls, every 2 numbers need to be exchanged, and at this time it degenerates into bubble sorting.
The space complexity is O(n)
and the average time complexity is: O(logn)Time complexity : O(nlogn)
Since quick sort uses recursive calls, calculating its time complexity also requires recursive algorithm calculationsThe average time complexity is O(nlogn), the worst time complexity is O(n*n), and the auxiliary space is O(logn)< Each time an extra space is allocated, and there are logn times in total> Divided into two sections each time
, Then the number of points is logn, and each processing requires n calculations, so the time complexity is nlogn!
According to the average case, it is O(nlogn), because in the case of equal probability of data distribution, for a single data, it will be placed in the correct position after logn times of movement.
The worst is O(n^2). In this case, the array is just reversed, and then every time you go to the middle element, you always take the maximum or minimum.