Question: In 13.1, an example of recursion is found in the getArea() method of the Triangle class. This method uses recursion to find the area of
In 13.1, an example of recursion is found in the getArea() method of the Triangle class. This method uses recursion to find the area of a triangle with a given width.
public int getArea() { if (width == 1) { return 1; } else { Triangle smallerTriangle = new Triangle(width - 1); int smallerArea = smallerTriangle.getArea(); return smallerArea + width; }
Using this example, outline, but do not implement, a recursive solution for finding the smallest value in an array. For example, suppose we have an Integer array with elements [12, 15, 28, 32, 3, 7, 21]. Outline how we can use recursion to find the smallest element, 3, in the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
