Question DSA-BST-0004
EasyWhat is the output of this code?
class Node:
def __init__(self, v, l=None, r=None):
self.v, self.l, self.r = v, l, r
def insert(n, v):
if not n:
return Node(v)
if v < n.v:
n.l = insert(n.l, v)
else:
n.r = insert(n.r, v)
return n
root = None
for v in [50, 30, 70, 20, 40, 60, 80]:
root = insert(root, v)
n = root
while n.l:
n = n.l
print(n.v)
- A.
20
- B.
50
- C.
Show answer and explanation
Answer: A
The minimum is found by going left from the root: 50 → 30 → 20.