How to convert a binary tree to binary search tree in-place, i.e., we cannot use any extra space

前端 未结 11 1107
借酒劲吻你
借酒劲吻你 2021-01-31 22:12

How to convert a binary tree to binary search tree in-place, i.e., we cannot use any extra space.

11条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 22:21

    Do inorder traversal of the binary tree and store the result. sort the result in acending order form the binary search tree by taking middle element of the sorted list as root( this can done using binary search). so we get balanced binary search tree.

提交回复
热议问题