Function to construct segment tree from given array . This function allocates memory for segment tree and calls constructSTUtil ( ) to fill the allocated memory
public static int [ ] constructSegmentTree ( int [ ] arr ) { int height = ( int ) Math . ceil ( Math . log ( arr . length ) / Math . log ( 2 ) ) ; int size = 2 * ( int ) Math . pow ( 2 , height ) - 1 ; st = new int [ size ] ; constructST ( arr , 0 , arr . length - 1 , 0 ) ; return st ; }