Question DSA-BST-0009
MediumWhat 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.r
while n.l:
n = n.l
print(n.v)
- A.
50
- B.
60
- C.
Sign up free to see the answer and a step-by-step explanation.