Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementation of binary tree

The following text is snippet from algorithms book.

We could draw the binary trees using rectangular boxes that are customary for linked lists, but trees are generally drawn as circles connected by lines because they are actually graphs. We also do not explicitly draw NULL links when referring to trees because every binary tree with N nodes would require N+1 NULL links.

My question is what does author mean every binary tree with N nodes would require N+1 null links? how author came with N+1 number?

like image 304
venkysmarty Avatar asked Dec 17 '22 10:12

venkysmarty


1 Answers

If you have a tree of 1 node, there are 2 null links (left and right on the root). If you add a node to either left or right, you have filled 1 null and added 2 more. This continues on ad infinitum, therefore for each node added you net 1 extra null leaf.

like image 95
Nick Larsen Avatar answered Dec 25 '22 23:12

Nick Larsen