int F(int A[], int left, int right) { right) return A[left]; left (right-left)/2; Draw the recursion...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
int F(int A[], int left, int right) { right) return A[left]; left (right-left)/2; Draw the recursion tree that results from the call F(A=[3, 5, 2, 4, 8, 9, 3, 4], 0, 7), and explain what this function computes as its output in general. Ex: unlucky(6789)→ true unlucky(5) → false if (left int middle int x = F(A, left, middle); int y = F(A, middle+1, right); if (x >y) return x; else return y; } //end-F 2. In order to find the largest element of a given array A[0..n-1) of size n, consider the following recursive algorithm: We first find the largest element of A[1..n-1] and compare the result with A[0] to find the overall largest element. Write the following Java function to solve this problem. Initial call to the function will be findMax(arr, 0); Assume that the array has at least one element. int findMax(int [] arr, int index); 3. Write a recursive function unlucky that returns true if the first two (leftmost) digits of the positive integer parameter add up to 13, else returns false. The function unlucky returns false if the parameter has fewer than 2 digits. bool unlucky(int n); unlucky(23456356) → false Ex: sum Digit(5149835)→ 48 biggest Digit(35) 0 4. Write a recursive function removeOddDigits that takes a positive integer and returns a new integer with all odd digits of the input removed. int removeOddDigits(int n); Rules: • The answers are to be hand-written on paper & submitted in class • Do NOT forget to put your name & id on your homework • Late submissions will NOT be accepted • Please do NOT cheat (for your own benefit)! int F(int A[], int left, int right) { right) return A[left]; left (right-left)/2; Draw the recursion tree that results from the call F(A=[3, 5, 2, 4, 8, 9, 3, 4], 0, 7), and explain what this function computes as its output in general. Ex: unlucky(6789)→ true unlucky(5) → false if (left int middle int x = F(A, left, middle); int y = F(A, middle+1, right); if (x >y) return x; else return y; } //end-F 2. In order to find the largest element of a given array A[0..n-1) of size n, consider the following recursive algorithm: We first find the largest element of A[1..n-1] and compare the result with A[0] to find the overall largest element. Write the following Java function to solve this problem. Initial call to the function will be findMax(arr, 0); Assume that the array has at least one element. int findMax(int [] arr, int index); 3. Write a recursive function unlucky that returns true if the first two (leftmost) digits of the positive integer parameter add up to 13, else returns false. The function unlucky returns false if the parameter has fewer than 2 digits. bool unlucky(int n); unlucky(23456356) → false Ex: sum Digit(5149835)→ 48 biggest Digit(35) 0 4. Write a recursive function removeOddDigits that takes a positive integer and returns a new integer with all odd digits of the input removed. int removeOddDigits(int n); Rules: • The answers are to be hand-written on paper & submitted in class • Do NOT forget to put your name & id on your homework • Late submissions will NOT be accepted • Please do NOT cheat (for your own benefit)!
Expert Answer:
Related Book For
Digital Design and Computer Architecture
ISBN: 978-0123944245
2nd edition
Authors: David Harris, Sarah Harris
Posted Date:
Students also viewed these programming questions
-
How to write a formal refusal letter letting him/her know your decision with example?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
KYC's stock price can go up by 15 percent every year, or down by 10 percent. Both outcomes are equally likely. The risk free rate is 5 percent, and the current stock price of KYC is 100. (a) Price a...
-
Who was the petitioner? Who was the respondent? b. In what year was the case heard? c. What tax years did the case address? d. Who was the judge in the case? e. What was the basic issue in the case?...
-
Is it condensation or vaporization that occurs on the warm outside coils of an operating air conditioner?
-
During your collaborative writing group meetings, keep a log of events. Record specific observations of both effective and ineffective things that group members do. Then evaluate the performance of...
-
Fraud Bingo Be a Sleuth: Use your answer to "catch" one of the first and most famous fraudsters: A T Ohio Congressman who has 2002 act named after him that responded to Enron crisis CED in big fraud...
-
Food Court Inc. (FCI) is a business in Boston, Massachusetts that offers meal plans to college students. Students, or their families, buy debit cards with fixed amounts that they can use to purchase...
-
2) Consider two firms AAA and BBB. Each firm needs to borrow $1M. AAA wants to borrow at a fixed interest rate while BBB wants to borrow at a floating interest rate. AAA can borrow either at 6% or at...
-
Lawrence is a 16-year-old youth who was found guilty of vandalism and assault. He was convicted of breaking into his school with two friends and writing insulting slogans on the hallway walls. He was...
-
Derrick Iverson is a divisional manager for Holston Company. His annual pay raises are largely determined by his divisions return on investment (ROI), which has been above 20% each of the last three...
-
Discuss the following verbal communication techniques and how you would use them within your practice as an educator and give two examples for each. Tone of voice Verbal cues Open and closed...
-
1.King Corp., uses 10,000 units of Part X to be used in its production cycle.King can make or buy Part X. If King buys the part from Utica Company, King could not use the released facilities in...
-
Suppose you are the Google manager in charge of making the decision about whether to introduce self-driving cars as a product for the general public. Suppose that if the car is introduced, there is a...
-
Elsinore Electronics is a decentralized organization that evaluates divisional management based on measures of divisional contribution margin. Home Audio (Home) Division and Mobile Electronics...
-
Information to calculate the adjusted cash balance for Everest Climbing Gear is as follows: Cash balance per general ledger $4,000 Customer's cheque returned--NSF 150 Bank service charges 80 Deposits...
-
what is the main different between balance sheet and income statement of manufacturing company like general motor and service company like at&t and multinational corporation like Sysco and Oilfield...
-
1-Stern observed all of the following results EXCEPT _______ in his experiment. A-one of the recombinant phenotypes was associated with an X chromosome of normal length B-the number of car, B+ male...
-
Repeat Exercise 6.14 for the following machine code. $a0 and $a1 are the inputs. $a0 contains a 32-bit number and $a1 is the address of a 32-element array of characters (char).? Data from problem 14...
-
In this problem, you will explore the design of a 32-bit prefix adder. (a) Sketch a schematic of your design. (b) Design the 32-bit prefix adder in an HDL. Simulate and test your adder to prove that...
-
Repeat Exercise 5.57 for the FSM of Figure 3.31(b).? A CLK S So Y Reset (b)
-
Tracking Co. holds an HTM bond investment in Fields Corp. The carrying value of the investment is \(\$ 4,500\) at December 31, 2020. Tracking Co. estimates the present value of the amounts expected...
-
Refer to the information in Brief Exercise 14-34 except now assume that the company intends to sell the AFS securities. Determine the amount of impairment loss (if any) to record in income under the...
-
Determine the amount of impairment loss (if any) to record in income under the following three separate scenarios for an AFS debt investment. In all three cases, the company does not intend to sell...
Study smarter with the SolutionInn App