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--
In this issue, the editor will bring you about how to quickly sort the python binary tree. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
The binary tree looks like this in our impression.
Quick sort looks like this in our impression:
The two look different, the structure is not the same, how can it be related? according to our usual way of thinking, before thinking about what the computer does, we have to use the human brain to figure it out, and then the computer just simulates us.
The main idea of quick sorting is to select a number A (usually take every number in a random sequence), then put the number smaller than A to the left of A, and the number larger than A to the right of A. Then select the corresponding numbers and stand in line on the left and right.
Get an initial random sequence:
6,9,4,5,8,2,3,7,1 .
Let's choose a number and take the first number: 6. And then I don't want to loop on the right first, then change the position, then cycle on the left and then change the position.
Imagine that there is only a blank piece of paper in hand now, and then we start to sort by putting 6 in the middle, and then looking at it one by one after going there, we can see that the smaller ones are copied on the left side of 6, and the ones larger than 6 are copied on the right side of 6. The result of the first copy is as follows:
Now we have two new sequences: [4] and [9]. Then copy 4 and 9 in the middle, and then look at them one by one. The result of the second time is as follows:
Now we have two sequences with a total length greater than 1: [2, 3, 1], [8, 7]. Then copy 2 and 8 in the middle, and then look at them one by one after going there. The result of the third time is as follows:
After writing in this way, there is no new sequence, but it looks strange. If we add a connecting line to them, we will find that it has become a binary tree:
New order
You can walk through the binary tree in the middle order (first left, then middle, then right).
This is the relationship between binary tree and quick sort.
This is how to quickly sort the python binary tree shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow 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.