Skip to content

Commit 3e99fc1

Browse files
committed
change code to resolve errors
1 parent 42294c9 commit 3e99fc1

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

Diff for: data_structures/binary_tree/kth_smallest_value_in_a_binary_search_tree.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@ def __init__(self, data: int) -> None:
1212
self.left: Optional[Node] = None
1313
self.right: Optional[Node] = None
1414

15-
def display(tree: Optional[Node]) -> None: # In Order traversal of the tree
16-
"""
17-
>>> root = Node(1)
18-
>>> root.left = Node(0)
19-
>>> root.right = Node(2)
20-
>>> display(root)
21-
0
22-
1
23-
2
24-
>>> display(root.right)
25-
2
26-
"""
15+
def display(tree: Optional[Node]) -> None:
2716
if tree:
2817
display(tree.left)
2918
print(tree.data)
@@ -33,7 +22,6 @@ def kthSmallest(root: Node, k: int) -> int:
3322
"""
3423
In a BST, the Inorder Traversal returns ascending order of the data when traversed.
3524
Thus, store Inorder traversal in a list and return the k-1 th Index which is the Kth Smallest number in a BST.
36-
3725
"""
3826
stack = []
3927
temp = []
@@ -47,17 +35,17 @@ def kthSmallest(root: Node, k: int) -> int:
4735
root = stack.pop()
4836
temp.append(root.data)
4937
root = root.right
50-
return (temp[k-1])
38+
return temp[k-1]
5139

52-
def main() -> None: # Main function for testing.
40+
def main() -> None:
5341
tree = Node(5)
5442
tree.left = Node(3)
5543
tree.right = Node(6)
5644
tree.left.left = Node(2)
5745
tree.left.right = Node(4)
5846
tree.left.left.left = Node(1)
59-
k = int(input("Enter the value of K:"))
60-
print("The {}th Smallest Value in the BST is:".format(k), kthSmallest(tree, k))
47+
k = 2
48+
print(f"The {k}th Smallest Value in the BST is:", kthSmallest(tree, k))
6149
print("Tree is: ")
6250
display(tree)
6351

0 commit comments

Comments
 (0)