Merge Sort Tree - Tutorial

You can do Kth smallest number query in range L to R, in O(n * {\log}^{2}n) by building the merge sort tree on indices instead of the values. This solution doesn’t depend on the values of A[i], however large they may be.

For implementation details, one may refer to this code for MKTHNUM problem on Spoj.

21 Likes