Write a recursive body for the following static, generic method that computes and…
- User
Write a recursive body for the following static, generic method that computes and returns the size of a given Tree. You can use any of the Tree methods except for the iterator and the size kernel method. Note that the Tree must be restored, i.e., its outgoing value must be the same as its incoming value. 1 2 3 4 5 6 7 8 9 10 11 /**
- Returns the size of the given {@code Tree}.
- @param
-
code
the type of the {@code Tree} node labels - @param t
-
code
the {@code Tree} whose size to return - @return the size of the given {@code Tree}
- @ensures size = |t| / public static int size(Tree t) {...} Provide a second implementation of the size method above but this time make it an iterative (non-recursive) solution. You still cannot use the size kernel method in your solution. Write a recursive body for the following static, generic method that computes and returns the height of a given Tree. You can use any of the Tree methods except for the height kernel method (in particular, you can use the size method). Note that the Tree must be restored, i.e., its outgoing value must be the same as its incoming value. 1 2 3 4 5 6 7 8 9 10 11 /*
- Returns the height of the given {@code Tree}.
- @param
-
code
the type of the {@code Tree} node labels - @param t
-
code
the {@code Tree} whose height to return - @return the height of the given {@code Tree}
- @ensures height = ht(t) / public static int height(Tree t) {...} Write a recursive body for the following static method that computes and returns the largest integer in a given non-empty Tree. Note that the Tree must be restored, i.e., its outgoing value must be the same as its incoming value. 1 2 3 4 5 6 7 8 9 10 11 12 13 /*
- Returns the largest integer in the given {@code Tree}.
- @param t
-
code
the {@code Tree<Integer>} whose largest integer to return - @return the largest integer in the given {@code Tree}
- @requires |t| > 0
- @ensures
- max is in labels(t) and
- for all i: integer where (i is in labels(t)) (i <= max)
- Assistant