Mar 17, 2016 08:26 AM
(This post was last modified: Mar 17, 2016 08:26 AM by humanjas.)
Code
1 public int pathlength(Tree t) {
2 return pathlength(t.root(), 0);
3 }
4 private int pathlength(Node v, int depth) {
5 if (v == null) return depth;
6 int result = depth;
7 for (Node c: v.children())
8 result += pathlength(c, depth+1);
9 return result;
10 }I started with the base case, which is a constant 'c1'.
Then they have a recursive call which is 'h' times a constant 'c2'. 'h' is the amount of children of the root.
But how do you continue with this?
Thanks in advance.

