title: Array size in segment tree Data structure
body: <p>In segment tree, we build segment tree above an array.
  <br>For Example, If array size is 8 [0-7] indexing.<br>
  Number of nodes in segment tree is 15 i.e., 1,2,4,8 in 1st,2nd,3rd,4th levls<br><br>
  <a href="https://i.stack.imgur.com/xeIcl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xeIcl.png" alt="enter image description here"></a><br>
  But in a problem, if I declare structure array size as <code>seg tree[2*N + 1]</code> its giving wrong answer whereas if I declare it as below</p>
  
  <pre><code>struct seg{ 
   int sum;
  };
  seg tree[4*N + 1];
  </code></pre>
  
  <p>Its giving wrong answer. My doubt is that [2*N] is sufficient, Then why is it giving wrong answer.
  <a href="https://i.stack.imgur.com/76zCb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/76zCb.jpg" alt="enter image description here"></a><br>Node segment(1-1) having number 9 its parent have number 4. So left child is 2*N right child is 2*N+1</p>