我在查找平均和最壞情況時間複雜度方面有點困難。所以我做了這個BST節點刪除與以下邏輯計算BST節點移除的時間複雜度
當您刪除在二叉搜索樹中的節點,有3種情況
1> The node to delete has no children. That's easy: just release its resources and you're done. Time complexity O(1)
2> The node has a single child node. Release the node and replace it with its child, so the child holds the removed node's place in the tree. Time complexity O(1)
3> The node has two children. Find the right-most child of node's left subtree. Assign its value to root, and delete this child. **Here time compexity can be maximum O(N)**
To find the node to be deleted can be **maximum O(N)**
那麼,你如何計算總平均和最壞時間複雜度? ?
這是一棵平衡樹嗎?節點是O(n)。 – 2012-08-10 12:16:12
在這種情況下,'N'是什麼? – 2012-08-10 12:17:21
@KolyolyHorvath ...我錯過了一個點.....它不是一個平衡的樹......我只需進行必要的編輯... – Dilletante 2012-08-10 12:23:57