Skip to content

Commit d7e7097

Browse files
author
Partho Biswas
committed
Iterative_In-order_Traversal
1 parent 4d1fc26 commit d7e7097

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ If you have any questions about the solutions you can find here, feel free to co
283283
|---| ----- | -------- | -------- | -------- |
284284
|01| [Invert_Binary_Tree](algoexpert.io/questions/Invert_Binary_Tree.md) | [Python](algoexpert.io/python/Invert_Binary_Tree.py)|
285285
|02| [Max_Path_Sum_In_Binary_Tree](algoexpert.io/questions/Max_Path_Sum_In_Binary_Tree.md) | [Python](algoexpert.io/python/Max_Path_Sum_In_Binary_Tree.py) |
286+
|03| [Iterative_In-order_Traversal](algoexpert.io/questions/Iterative_In-order_Traversal.md) | [Python](algoexpert.io/python/Iterative_In-order_Traversal.py) |
286287

287288

288289
### Dynamic Programming
@@ -381,6 +382,7 @@ If you have any questions about the solutions you can find here, feel free to co
381382
|03| [Caesar_Cipher_Encryptor](algoexpert.io/questions/Caesar_Cipher_Encryptor.md) | [Python](algoexpert.io/python/Caesar_Cipher_Encryptor.py)|
382383
|04| [Longest_Substring_Without_Duplication](algoexpert.io/questions/Longest_Substring_Without_Duplication.md) | [Python](algoexpert.io/python/Longest_Substring_Without_Duplication.py)|
383384
|05| [Underscorify_Substring](algoexpert.io/questions/Underscorify_Substring.md) | [Python](algoexpert.io/python/Underscorify_Substring.py)|
385+
|06| [Pattern_Matcher](algoexpert.io/questions/Pattern_Matcher.md) | [Python](algoexpert.io/python/Pattern_Matcher.py)|
384386

385387

386388
### Tries
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
# O(n) time | O(1) space
4+
def iterativeInOrderTraversal(tree, callback):
5+
previousNode = None
6+
currentNode = tree
7+
while currentNode is not None:
8+
if previousNode is None or previousNode == currentNode.parennt:
9+
if currentNode.left is not None:
10+
nextNode = currentNode.left
11+
else:
12+
callback(currentNode)
13+
nextNode = currentNode.right if currentNode.right is not None else currentNode.parennt
14+
elif previousNode == currentNode.left:
15+
callback(currentNode)
16+
nextNode = currentNode.right if currentNode.right is not None else currentNode.parennt
17+
else:
18+
nextNode = currentNode.parennt
19+
previousNode = currentNode
20+
currentNode = nextNode
21+
22+
23+
24+
25+

algoexpert.io/python/Pattern_Matcher.py

Whitespace-only changes.

0 commit comments

Comments
 (0)