Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

int F(int AD), int left, int right) { right) return A[left]; left (right-left)/2; Draw the recursion tree

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)!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Digital Design and Computer Architecture

Authors: David Harris, Sarah Harris

2nd edition

9789382291527, 978-0123944245

More Books

Students also viewed these Programming questions

Question

Draw the Bode plot for the network function j4 + 1 J20+ 1 H ( j ) -

Answered: 1 week ago