-1

I read various tutorials on BIT.. topcoder etc ones, all operations are well explained in those, but m not getting the way BIT is created i.e.

Given an array, 1-D, how e have to kake the corresponding BIT for that? ex. if the array is 10 8 5 9 1 what will the BIT for this?

I am a beginner, so apologies if my question sounds stupid but i am not understanding this. So, please help.

user3004790
  • 748
  • 7
  • 10

1 Answers1

0

You simply start with an empty structure (allo 0s) and insert each element. Complexity is O(NLogN) but likely the rest of your algotihm is also NLogN so it will not matter.

Sorin
  • 11,863
  • 22
  • 26
  • How i have to insert? Please explain with an example. – user3004790 Dec 11 '13 at 10:21
  • @user3004790 you said you know that already. Check out the tutorials you mentioned. – Sorin Dec 11 '13 at 10:36
  • I read the topcoder one ... My doubt goes like while making the bit[], idx is some index of BIT. r is a position in idx of the last digit 1 (from left to right) in binary notation. tree[idx] is sum of frequencies from index (idx - 2^r + 1) to index idx , then how is this true if idx is 3?? Because if idx is 3, r is 0 then idx - 2^r +1 is 4, so, bit[3] will have summation of frequencies from 4 to 3?? I know m getting something wrong.. but please i would like to clarify! – user3004790 Dec 11 '13 at 12:38