Skip to content

Commit 5b5d692

Browse files
author
Joseph Luce
authored
Update 437_path_sum_III.md
1 parent 1fb8235 commit 5b5d692

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

leetcode/easy/437_path_sum_III.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# 437. Path Sum III
22

33
## Brute Force Top Down Recursive Solution
4-
- Runtime: O(3^N)
5-
- Space: O(3^N)
4+
- Runtime: O(2^N)
5+
- Space: O(2^N)
66
- N = Number of nodes in tree
77

88
Thinking about the brute force method, for every node in the tree, traverse their left child and right child to find the target sum.
@@ -13,8 +13,10 @@ This is similar to a DFS implementation.
1313

1414
The runtime can be calculated in this way.
1515
For each recursive call, we want to traverse the left and right children down to the leaf nodes, this is O(N) runtime.
16-
Since we would have to do this again but for the left and right children, it about O(N-1) for each.
17-
So we basically have O(N) three times which means O(3^N).
16+
Since we would have to do this again but for the left and right children, it about O(log(N)) for each.
17+
So we basically have O(N), O(log(N)), O(log(N)).
18+
The two O(log(N)) can be simplified to O(N-1).
19+
So O(N) and O(N-1) per call = O(2^N)
1820

1921
Remember the formula for recursion, (Number of calls ^ (Big O per call))
2022

0 commit comments

Comments
 (0)