Please help me with some doubts, I was reading 2D BIT, gfg implementation https://www.geeksforgeeks.org/two-dimensional-binary-indexed-tree-or-fenwick-tree/
In the updateBit and getSum function inner loop, "y" is not initialized again, can someone explain me how is it working and what is the need of outer loop as the same work can be done with the help of an "if" statement.
Thanks in advance..
That's just wrong, you should initialize y on each step with the value of the query. You better check the link to topcoder in a reference section of this article.
Thank you for replying.
I have a doubt in the tutorial, https://www.topcoder.com/community/data-science/data-science-tutorials/binary-indexed-trees/, in the "Find index with given cumulative frequency" section why are we not checking for the bound errors as tIdx can be greater than MaxVal and may give segmentation error while accessing tree[tIdx].
Thanks in advance..
Yeah, size of BIT should be at least (MaxVal + 1) rounded up to the power of 2 for this algorithm to work correctly.
Or you can check for bounds, returning the sum of the whole BIT if the index is greater.
Thanks