previous | start | next

Recursive size method

The size method illustrates the technique.

The size of the tree can be split into subproblems of the same kind:

 size of tree = size of left subtree + size of right subtree + 1 (for the root)
   

Java allows methods to be overloaded, which means that methods in the same class can have the same name. However, they must have different parameter lists. That allows the compiler to know which one is called.

In particular, the public and its private recursive helper can have the same name.



previous | start | next