Skip to content

Commit 640d69e

Browse files
author
Partho Biswas
committed
no message
1 parent 3b80ade commit 640d69e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ BFS, DFS, Dijkstra, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spa
900900
|05| [Lowest_Common_Manager](algoexpert.io/questions/Lowest_Common_Manager.md) | [Python](algoexpert.io/python/Lowest_Common_Manager.py) |
901901
|06| [Number_Of_Possible_Binary_Tree_Topologies](algoexpert.io/questions/Number_Of_Binary_Tree_Topologies.md) | [Python](algoexpert.io/python/Number_Of_Possible_Binary_Tree_Topologies.py) |
902902
|07| [Interweaving_Strings](algoexpert.io/questions/Interweaving_Strings.md) | [Python](algoexpert.io/python/Interweaving_Strings.py) |
903+
|08| [Number_Of_Binary_Tree_Topologies](algoexpert.io/questions/Number_Of_Binary_Tree_Topologies.md) | [Python](algoexpert.io/python/Number_Of_Binary_Tree_Topologies.py) |
903904

904905
</p>
905906
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def numberOfBinaryTreeTopologies(n, cache={0: 1}):
2+
if n in cache:
3+
return cache[n]
4+
numbersOfTree = 0
5+
for leftTreeSize in range(n):
6+
rightTreeSize = n - 1 - leftTreeSize
7+
numOfLeftTree = numberOfBinaryTreeTopologies(leftTreeSize, cache)
8+
numOfRigntTree = numberOfBinaryTreeTopologies(rightTreeSize, cache)
9+
numbersOfTree += numOfRigntTree * numOfLeftTree
10+
cache[n] = numbersOfTree
11+
return numbersOfTree

0 commit comments

Comments
 (0)