Hi. I'm new to segment tree. im solving a problem in which we have to find most frequent element in given range so for the below testcase im trying to constructing tree but i stuck.
-1 -1 1 1 1 1 3 8 8 8 [i,j] is range of segment and x is the element that occur frequently and y is the count of x. [i,j]=[x,y] [0,0]=[-1,1] [1,1]=[-1,1] [0,1]=[-1,2]// because the sub tree[0,0]->x==[1,1]-->x so we added value. [2,2]=[1,1] [0,2]=[-1,2]// becuase the subtree [0,1][2,2] have value [-1,2] & [1,1] so first set have higher value [3,3]=[1,1] [4,4]=[1,1] [3,4]=[1,2]// same reason as [0,1] set problem occur here while updating the value of [0,4] [0,4] has 2 child [0,2]=[-1,2] & [3,4]=[1,2] so updating the set we can determine which value should belongs to [0,4] and set [2,2]=[1,1] which we neglect. then how to update value [0,4] while intializing the segment tree??? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/EPX4mfsu6_sJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
