0

I have to prove that in binary search tree, number of nodes with two children is one less than number of leaves. I found some proofs by induction on the internet, but I wanted to approach this problem less 'mathematically'. So I thought of this:

-we have just a single root (which is a leaf), so we have 1 leaf and 0 nodes with two children, OK.

-when we have a node with no children, and we add a child to it - number of leaves stays the same (node that we added to is not a leaf anymore, but new child is) and number of nodes with two children stays the same.

-when we have a node with 1 child and we add 2nd child to it, number of leaves increases, but number of nodes with two children also increases, so +1 here and +1 there, still the difference of 1, OK.

And that's it, there is no other option to add. So, at the start that property 'works' for just a single leaf (root), and then no matter how we add to this tree - property will still be preserved. Is that enough to prove that there is one more leaf than nodes with two children? Should I add something (maybe mention deleting)? I know this could probably be written as normal mathematical induction in some way, but I wanted to avoid too much formality, so is this a 'legit' way to prove that fact? Thanks in advance.

Haratino
  • 1
  • 3

1 Answers1

0

Your explanation is basically a proof by induction, so yes, I would say that it is 'legit'. Your first comment about when we have a single root is the base case. Then given a binary search tree for which the property holds, you explain that after modifying the tree by adding one more node, the property still holds. So that's the induction step.

MAS
  • 96
  • 6