Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf201a57

Browse files
authored
clarify space complexity for dfs trees (neetcode-gh#3761)
1 parent232acfa commitf201a57

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

‎articles/balanced-binary-tree.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ class Solution {
526526
###Time & Space Complexity
527527

528528
* Time complexity: $O(n)$
529-
* Space complexity: $O(n)$
529+
* Space complexity: $O(h)$
530+
* Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$
531+
* Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$
532+
533+
>Where $n$ is the number of nodes in the tree and $h$ is the height of the tree.
530534
531535
---
532536

‎articles/binary-tree-diameter.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,11 @@ class Solution {
520520
###Time & Space Complexity
521521

522522
* Time complexity: $O(n)$
523-
* Space complexity: $O(n)$
523+
* Space complexity: $O(h)$
524+
* Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$
525+
* Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$
526+
527+
> Where $n$ is the number of nodes in the treeand $h$ is the height of the tree.
524528

525529
---
526530

‎articles/depth-of-binary-tree.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ class Solution {
176176
###Time & Space Complexity
177177

178178
* Time complexity: $O(n)$
179-
* Space complexity: $O(n)$
179+
* Space complexity: $O(h)$
180+
* Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$
181+
* Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$
182+
183+
>Where $n$ is the number of nodes in the tree and $h$ is the height of the tree.
180184
181185
---
182186

‎articles/same-binary-tree.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ class Solution {
191191
###Time & Space Complexity
192192

193193
* Time complexity: $O(n)$
194-
* Space complexity: $O(n)$
194+
* Space complexity: $O(h)$
195+
* Best Case ([balanced tree](https://www.geeksforgeeks.org/balanced-binary-tree/)): $O(log(n))$
196+
* Worst Case ([degenerate tree](https://www.geeksforgeeks.org/introduction-to-degenerate-binary-tree/)): $O(n)$
197+
198+
> Where $n$ is the number of nodes in the treeand $h$ is the height of the tree.
195199

196200
---
197201

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp