Question
Diagram the full state of memory each time a call to search begins (after lines 10 but before line 12 inside search) and immediately after
Diagram the full state of memory each time a call to search begins (after lines 10 but before line 12 inside search) and immediately after a call to search returns back a to the original calling context (can occur after lines 7, 20, and 22 resolve which returns back to the point in the function that called it). Label each stack frame clearly with a function name, the action that resulted in the current state, and the depth of the recursion,e.g. main, search call 1, search call 2, search return 1, search return 2, etc., where applicable, and if a sub-diagram represents the state immediately after a call return, show the value returned from the previous call to the current frame by using an arrow from the previous frame to the current frame which must be labeled with the value that was returned. You are encouraged to draw this diagram using software; however, you may submit a hand-drawn solution as long as it has a high enough resolution to be easily read.
1 public class Searcher { static int[] data = {2, 3, 5, 8, 13, 21, 34, 55, 89, 144}; public static void main(String[] argv ) { boolean found; int value = 40; found = search ( data, value, 0, data.length-1 ); System.out.println("found=" + found ); 10 11 static boolean search ( int[] A, int value, int start, int end ) { if ( start > end ) { return false; 13 14 15 int mid = (start + end) / 2; 17 19 20 21 if ( A[mid] == value ) { return true; } else if( valueStep by Step Solution
There are 3 Steps involved in it
Step: 1
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