Difference between revisions of "Tail Recursion Assignment"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
| + | =Motivation= | ||
| + | Sometimes we choose tail recursion for the performance improvement which can be achieved by a language implementation optimization. Sometimes the tail recursive version is the cleaner implementation. Reverse is an example where the right way to build it is tail recursive. | ||
=Code To Implement= | =Code To Implement= | ||
==Reverse== | ==Reverse== | ||
Revision as of 01:52, 6 October 2020
Contents
Motivation
Sometimes we choose tail recursion for the performance improvement which can be achieved by a language implementation optimization. Sometimes the tail recursive version is the cleaner implementation. Reverse is an example where the right way to build it is tail recursive.
Code To Implement
Reverse
| class: | Reverse.java | |
| methods: | reverse | |
| package: | tail.assignment | |
| source folder: | src/main/java |
public static <E> ImmutableList<E> reverse(ImmutableList<E> original)
You will want to build a private static helper method which is tail recursive for reverse to invoke.
Test
| class: | ReverseTestSuite.java | |
| package: | tail.assignment | |
| source folder: | src/test/java |