NB Two group----heap sorting

Source: Internet
Author: User

Heap sort forward--a brief introduction to the tree and the two fork tree

Special and commonly used tree--two-fork tree

Two special two-fork trees

How to store binary trees

A summary of two-fork tree

Heap Sort

Heap this thing ....

Heap sorting process:

Algorithm program for heap sequencing (the program needs to be understood):

defSift (Data,low,high):#Adjustment functioni = Low#the root of the tree is the father, the only leader herej = 2 * i + 1#the left child of the root is the son, this is the little leader.TMP = Data[i]#take the root out to make adjustments, lead here     whileJ <= High:#High is actually the right son of the root (that is, the last son), if j= high means there is no right son, which means there must be a son in        ifJ < High andDATA[J] < Data[j + 1]:#J < High represents a right son, Data[j] < Data[j + 1] indicating that the right son is bigger than his left son.J + = 1#This j becomes the right son, that is, if there is a greater value than J, then J becomes the greater value.        ifTMP < DATA[J]:#If the leader can't do it,Data[i] = Data[j]#the small leader of the upperi = j#small leaders become big leadersj = 2 * i + 1#Small leaders turn into little leaders        Else:#if the leader is competent             Break #Well, then, stay.Data[i] = tmp#At the end I will definitely have a vacancy here, so no matter who the TEM is, it's going to occupy this vacancy.

NB Two group----heap sorting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.