In segment trees , we divide the array into 2 halves and carry it on recursively. Why can’t they be divided into,,let’s day , 3 halves, representing 3 segments. Why is it a binary tree?
Why segment tree has to be a binary tree only, why can’t it be ternary, or say n-ary tree, where n >2?
83 views Asked by aman shrivastava At
1
Well, You can ask the same question about binary search or any binary decision based data structure like a binary search tree. There are two main reasons for this.
You might think that breaking an array into 3 parts instead of 2 might get you a speed up, but this not true. Since if you break an array into 3 parts each one third of the original size, then you might in the worst case recurse on 2/3rds size of the orignal array always, there by making the running time worst than binary search.