• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jul 20th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. if (node.key == data) :
2.     return 1
3.
4. downlevel= 1+getLevel(node.left,
5.                          data)
6. if (downlevel != 0) :
7.     return downlevel
8.
9. downlevel = 1+getLevel(node.right,
10.                          data)
11.
12. return downlevel
13.
14. path.append(node.key)
15.
16. if node.key == k :
17.     return True
18.
19. if ((node.left != None and pathToNode(node.left, path, k)) or
20.         (node.right!= None and pathToNode(node.right, path, k))):
21.     return True
22.
23. path.pop()
24. return False
25.
26. path1 = []
27. pathToNode(node, path1, x)
28.
29. path2 = []
30. pathToNode(node, path2, y)
31.
32. i=0
33. while i<len(path1) and i<len(path2):
34.     if path1[i] != path2[i]:
35.         break
36.     i = i+1
37.
38.
39. return (len(path1)+len(path2)-2*i)
40.
41. def __init__(self, item):
42.     self.key=item
43.     self.left = None
44.     self.right = None
45.
46. list = []
47.
48. if (start > end) :
49.
50.     list.append(None)
51.     return list
52.
53. for i in range(start, end + 1):
54.     leftSubtree = constructTrees(start, i - 1)
55.     rightSubtree = constructTrees(i + 1, end)
56.     for j in range(len(leftSubtree)) :
57.         left = leftSubtree[j]
58.         for k in range(len(rightSubtree)):
59.             right = rightSubtree[k]
60.             node=newNode(i)
61.             node.left = left
62.             node.right = right
63.             list.append(node)
64. return list
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top