Understanding segment trees and BIT ?

hello friends i have read segment trees from various websites , i am able to understand the approach, idea and need of segment trees can someone please explain how to implement them and code them , i need a well commented code , please help

Here and here.

Apart from the links @neo1tech9_7 specified, another application of segment trees is when you need to perform range queries and range update , i.e. when apart from queries, you need to perform multiple update operations on different ranges in the array. Here you will need lazy propagation. Here is a very easy to understand code.

These should help in understanding as well as implementing BIT.

  1. Topcoder tutorial (well commented code for all operations on BIT)
  2. range queries and fenwick trees (contains code & very well explained)
  3. intuition behind fenwick trees on stackoverflow

Problems related to BIT
answer on quora

Hope it helped :slight_smile:

Well range queries and range update should be learnt a little later I guess as they are not really easy to get at the start :stuck_out_tongue:

1 Like

I am new to segment trees and one of the first problems i solved involved range update, & the above blog helped me a lot in that, hence i mentioned it :slight_smile: