Answered step by step
Verified Expert Solution
Question
1 Approved Answer
a) Consider the following recursive methods. 01. public class Recursion { /* Assume that n is no less than 0 and no greater than
a) Consider the following recursive methods. 01. public class Recursion { /* Assume that n is no less than 0 and no greater than the length of the array a */ 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. public static boolean ml (int[] a, int n) { if (n 2 && num & divisor == 0)) return false; 21. 22. 23. } 24. } if (divisor (ii) (4 points) Describe what is returned by the method call m2 for any n such that n>=2. (iii) (10 points) Show the sequence of recursive calls to m1, including arguments, and the return value for each of the following calls to the method m1. A call m1 ({2, 6, 5}, 3) means that the first parameter integer array a has the values 2, 6, 5 and the second parameter has value 3. Call ml ({2, 6, 5}, 3) m1 ({23, 3, 7, 33}, 3) m1({23, 3, 7, 33}, 4) m1 ({6, 3, 17, 21, 33}, 5) m1({5}, 1) Sequence of recursive Return value calls to m1 (iv) (6 points) Describe what is returned by the method call m1 (arr, n) for any integer array arr and integer n such that 0 b) (15 points) Suppose that a piece of Java code is stored using a String array (e.g, String[] code). Each line is one element of this array. Assume there is a method boolean contains MethodCall (String line) that can check whether a line of code specified by the parameter line contains a method call or not. If the parameter line contains a method call, the method containsMethodCall returns true, otherwise returns false. /** * @precondition arr is non-null * @precondition max is non-negative. * @precondition count is non-negative */ public static boolean noMore ThanNMethod (String[] code, int index, int max, int count) Given the method header shown above, write a recursive method to check whether the parameter array code contains more than max methods. Specifically, if the number of method calls in the piece of code specified by the parameter code is more than the number specified by the parameter max, return false, otherwise return true. Use index to keep track of which array index is being inspected in each recursive call and, count as a counter of the number of method calls. Assume that the parameter arr is not null, the parameter max is non-negative and the parameter count is non-negative. Call the method containsMethodCall (String line) to check whether a line of code contains a method call or not. Assume that contains MethodCall works as intended. Assume that there is at most one method call in a line of code. Example: public static boolean ml (int[] a, int n) { if (n
Step by Step Solution
★★★★★
3.38 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
a i Sequence of recursive calls ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started