In segment tree, we build segment tree above an array.
For Example, If array size is 8 [0-7] indexing.
Number of nodes in segment tree is 15 i.e., 1,2,4,8 in 1st,2nd,3rd,4th levls
But in a problem, if I declare structure array size as seg tree[2*N + 1]
its giving wrong answer whereas if I declare it as below
struct seg{
int sum;
};
seg tree[4*N + 1];
Its giving wrong answer. My doubt is that [2*N] is sufficient, Then why is it giving wrong answer.
Node segment(1-1) having number 9 its parent have number 4. So left child is 2*N right child is 2*N+1