Блог пользователя Fear_Is_An_Illusion

Автор Fear_Is_An_Illusion, 9 лет назад, По-английски

Can anyone say the most time efficient method ?. Thanks and sorry if it is easy question.

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Should it be in-place? If not, you could create another tree and, while iterating through the binary tree, add nodes to the BST following the rules. Looks like O(n^2) in worst case (when you iterate through an ordered binary tree) and O(nlogn) in best case (when BST is balanced and adding takes logarithmic time).