Write a program to find depth of binary search tree without using recursion
Anonymous
Python implementation using a stack. def depth(root): st = [(root, 0)] maxd = 0 while len(st): node, dpt = st.pop() maxd = max(maxd, dpt) if node['left']: st.append((node['left'], dpt + 1)) if node['right']: st.append((node['right'], dpt + 1)) return maxd
Check out your Company Bowl for anonymous work chats.