pydsa.bst¶
insert ¶
insert(root: Optional[TreeNode], val: int) -> TreeNode
Insert a value into the BST and return the root.
Source code in pydsa/bst.py
9 10 11 12 13 14 15 16 17 18 | |
generate_random_bst ¶
generate_random_bst(
n: int, seed: Optional[int] = None
) -> Optional[TreeNode]
Generate a random BST with values 1..n inserted in random order.
Source code in pydsa/bst.py
21 22 23 24 25 26 27 28 29 30 31 32 | |
tree_to_list ¶
tree_to_list(
root: Optional[TreeNode],
) -> List[Optional[int]]
Convert BST to list using level-order traversal.
Source code in pydsa/bst.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
is_valid_bst ¶
is_valid_bst(root: Optional[TreeNode]) -> bool
Check if the tree is a valid BST using inorder traversal.
Source code in pydsa/bst.py
55 56 57 58 59 60 61 62 63 64 | |