Question DSA-BST-137
MediumWhat is the output of this code?
class N:
def __init__(self, v):
self.v, self.l, self.r = v, None, None
def ins(n, v):
if not n:
return N(v)
if v < n.v:
n.l = ins(n.l, v)
else:
n.r = ins(n.r, v)
return n
r = None
for v in [8, 3, 10, 1, 6, 14, 4, 7, 13]:
r = ins(r, v)
def floor(n, x):
best = None
while n:
if n.v == x:
return x
n.v < x:
best, n = n.v, n.r
:
n = n.l
best
(floor(r, ), floor(r, ), floor(r, ))
- A.
10 4 None
- B.
13 6 None
- C.
Sign up free to see the answer and a step-by-step explanation.