Big O of finding out if a binary tree is balanced (From CTCI Book)

前端 未结 2 1627
余生分开走
余生分开走 2021-01-14 03:45

In Cracking the Coding Interview 6th Edition there\'s a question (4.4) where you\'re suppose to find out if a binary tree is balanced, where balanced in this case means if a

2条回答
  •  花落未央
    2021-01-14 04:31

    Your algorithm time complexity is T(n) = 2T(n/2) + 1. Hence, time complexity of your algorithm would be T(n) = O(n). However, the correctness of your algorithm is under question.

提交回复
热议问题