Tree-like array

Source: Internet
Author: User

First, we need to understand how the numbers are stored in the computer.

In 68, for example, his binary is (68) 2=1000100. What about 68? Because the integers in the computer are in the complement notation (the complement is the original code plus one), so-68 is actually 68 bitwise inverse, the end plus a later result. The following table (ignores symbol bits):

Original Code 1 0 0 0 1 0 0

Anti-code 0 1 1 1 0 1 1

Complement 0 1 1 1 1 0 0

Let's put (68) 2 and (-68) 2 together and take a look:

1 0 0 0 1 0 0

0 1 1 1 1 0 0

found that the 0 of their end bands were as much.   So lowbit (x) =x&-x. (& is converted into binary and then performed and calculated, and && is directly performed and calculated)

Here is a more classic tree-like Array (BIT):

↓↓↓↓↓

Lowbit = 24 23 22 21 20

The following rules can be obtained:

1) For node I, if he is the left Dial hand node (bottom left upper right), then the number of his parent node is i+lowbit (i); if he is the right child node, the number of his parent node is i-lowbit (i). (I>=lowbit (i))

2) The odd lowbit are all 1 because their binary bits are 1 (that is, the factor is not 2). The following and so on: 2, 6, 10, 14 can be divisible by 21, 4, 12 divisible by 22 ... So their lowbit are 2, 3 ...

On the basis of the above rules, we create a new array C (A is the original array), it is easy to get:

Ci=ai-lowbit (i) +1+ai-lowbit (i) +2+......+ai

Example: C1=a1,c2=a1+a2,c3=a3,c4=a1+a2+a3+a4,......

Tree-like array

Related Article

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.