I'm constructing a binary tree for a sequence of data and the tree is store in a 1-based array. So if index of parent node is idx,
the left child is 2 * idx and the right is 2 * idx + 1.

Every iteration, I sort current sequence based on certain criteria, select the median element as parent, tree[index] = sequence[median], then do same operation on left(the sub sequence before median) and right(the subsequence after median) recursively....