build tree by sorted array