diff --git a/articles/balanced-binary-tree.md b/articles/balanced-binary-tree.md index 65a8aece1..c9c407ed0 100644 --- a/articles/balanced-binary-tree.md +++ b/articles/balanced-binary-tree.md @@ -526,7 +526,11 @@ class Solution { ### Time & Space Complexity * Time complexity: $O(n)$ -* Space complexity: $O(n)$ +* Space complexity: $O(h)$ + * Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$ + * Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$ + +> Where $n$ is the number of nodes in the tree and $h$ is the height of the tree. --- diff --git a/articles/binary-tree-diameter.md b/articles/binary-tree-diameter.md index d6c7ab0fe..3c73fbe92 100644 --- a/articles/binary-tree-diameter.md +++ b/articles/binary-tree-diameter.md @@ -520,7 +520,11 @@ class Solution { ### Time & Space Complexity * Time complexity: $O(n)$ -* Space complexity: $O(n)$ +* Space complexity: $O(h)$ + * Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$ + * Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$ + +> Where $n$ is the number of nodes in the tree and $h$ is the height of the tree. --- diff --git a/articles/depth-of-binary-tree.md b/articles/depth-of-binary-tree.md index d14965dba..efd76b64d 100644 --- a/articles/depth-of-binary-tree.md +++ b/articles/depth-of-binary-tree.md @@ -176,7 +176,11 @@ class Solution { ### Time & Space Complexity * Time complexity: $O(n)$ -* Space complexity: $O(n)$ +* Space complexity: $O(h)$ + * Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$ + * Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$ + +> Where $n$ is the number of nodes in the tree and $h$ is the height of the tree. --- diff --git a/articles/same-binary-tree.md b/articles/same-binary-tree.md index 05876d926..6cbfc12aa 100644 --- a/articles/same-binary-tree.md +++ b/articles/same-binary-tree.md @@ -191,7 +191,11 @@ class Solution { ### Time & Space Complexity * Time complexity: $O(n)$ -* Space complexity: $O(n)$ +* Space complexity: $O(h)$ + * Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$ + * Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$ + +> Where $n$ is the number of nodes in the tree and $h$ is the height of the tree. ---