You have learned that an invocation tree is an abbreviation for a collection of Java Execution Model frames. Each node of the tree shows the arguments and the result of a method invocation; such a node abbreviates a frame in ExecutionLand.
In your discussion of lists in lecture, you have now also been introduced to the box-and-pointer diagram, which is used as an abbreviation for interconnected linked list nodes in ObjectLand.
It is possible to combine invocation trees and box-and-pointer diagrams to summarize the execution of a list manipulation program. Consider the following pair of methods:
public IntList addProd (IntList L) { return addProdHelp (1, L); } public IntList addProdHelp (int n, IntList L) { if (isEmpty(L)) { return L; } else { IntList sublist = addProdHelp(n * head(L), tail(L)); return prepend(n + head(L), sublist); } }
The first method, addProd, takes an integer list and returns an integer list in which each element has had the product of the previous elements added to it. For instance, if L3 is the list whose printed representation is [3,5,2,4] then the result of addProd(L3) should be [4, 8, 17, 34] because:
To do this, addProd calls a helper method addProdHelp that takes two arguments: (1) a number n that is the product of all the elements processed thus far, and (2) a list of the elements still to be processed.
Assuming that L3 is the integer list whose printed representation is [3,5,2,4] (as described above), draw a combined invocation tree/box-and-pointer diagram that illustrates the invocation addProd(L3).