Question: Write a recursive method that tries to find target among the elements a[m],...,a[n-1] of a given array (any array, not necessarily sorted). public static int

Write a recursive method that tries to find target among the elements a[m],...,a[n-1] of a given array (any array, not necessarily sorted).

public static int search (int[] a, int m, int n, int target)

If found, the method should return the position of the target value; otherwise it should return -1. The base case is when the searching range is empty or consists of one element (m n). For the recursive case, split the searching range into two approximately equal halves and try to find the target in each of them. (this is supposed to be written in Java)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!