// Among indexes first...last, return index of the target. // If target is not present then return -1. // precondition: the elements of array are in descending order. static int find(int [] array, int first, int last, int target) if (first > last) { // one very short line } if (first == last) { // one line, using the conditional operator } int mid = (first+last+1)/2; %3D if (target <= array[mid]) { // one line, involving a recursive call } // one line, involving a recursive call

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 13RQ: How is an array stored in main memory? How is a linked list stored in main memory? What are their...
icon
Related questions
Question

In java 

i have some code for a method that finds the index of an integer that is passed in thet int is (target) the method also has the array called (array) and the first and last element of the array. also for this method to work the array has to be in descending order

"static int find(int [] array, int first, int last, int target)"

thats the method with all the variables that are passed to it 

my guess is that the first if statement just will have a short line that is

"return -1;" because since the array has to be in descending order the first element cant be greater then the last element in the array but im confused on the rest because i cant find a way to make them one line codes with the conditions that i have to meet in the comments any help would be aprreaciated

// Among indexes first...last, return index of the target.
// If target is not present then return -1.
// precondition: the elements of array are in descending order.
static int find(int [] array, int first, int last, int target)
if (first > last) {
// one very short line
}
if (first == last) {
// one line, using the conditional operator
}
int mid = (first+last+1)/2;
if (target <= array[mid]) {
// one line, involving a recursive call
}
// one line, involving a recursive call
Transcribed Image Text:// Among indexes first...last, return index of the target. // If target is not present then return -1. // precondition: the elements of array are in descending order. static int find(int [] array, int first, int last, int target) if (first > last) { // one very short line } if (first == last) { // one line, using the conditional operator } int mid = (first+last+1)/2; if (target <= array[mid]) { // one line, involving a recursive call } // one line, involving a recursive call
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning