How to calculate the upper-layer number of such a topology?-php Tutorial

Source: Internet
Author: User
How can I calculate the numbers on the upper layer, and each layer has two nodes? now, how can I know that the upper layer of 8 has 1, 2, and 4?
How can we calculate 1, 2, and 5 on 10?

Sincerely ask for advice!


Reply to discussion (solution)

Each number records its parent
The parent level of 1 is 0.
The parent level of 2 and 3 is 1.
4. the parent class of 5 is 2, 6, and 7 is 3.
And so on

Then recursively look for a number of parent levels until the parent level is 0.

Complete binary tree

$ N = 10 ;//
While ($ n> 1 ){
$ N = floor ($ n/2 );
Echo $ n ."";
}
?>

Let's take a look at the binary tree section of the data structure.

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.