Interview Bootcamp
Ask Author
Back to course home

0% completed

Vote For New Content
Paritosh Paliwal
In insert method, why are we using < operator instead of <= operator ?

Paritosh Paliwal

Nov 17, 2024

In order to meet BST conditions, value of left subtree must be less than or equal to parent node. The insertion code in python3 only checks for < condition but for equals to condition it assigns the node in right subtree.

Correct code should be ?

while current is not None: parent = current if value > current.data: current = current.right else: current = current.left

2

0

Comments
Comments