the art of
Algorithm
Notes on Analysis and Design



Size of Tree

Python program for determining size of tree.Size of tree is number of elements in a tree.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Node:
	def __init__(self,key):
		self.left=None
		self.right=None
		self.data=key
def size(node):
	if node is None:
		return 0
	else:
		return (size(node.left)+1+size(node.right))
#driver program to test above function
node=Node(1)
node.left=Node(2)
node.right=Node(3)
root.left.left  = Node(4)
root.left.right = Node(5)