Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There is 16 question about this simple class , but I\"m not understanding it The

ID: 3654810 • Letter: T

Question

There is 16 question about this simple class , but I"m not understanding it

The question at the comments ,, like // 1- why ? // 2- what ,,, it's 16 questions

Please answer them carefully :)

The class is here :http://wikisend.com/download/936170/OrdArray.java

Or you can find it here :

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package ds_lab_2;


/**

*

* @author

*/

public class OrdArray {

private long[] a; // ref to array a

private int nElems; // number of data items

/////////////////////////////////////////////////////

public OrdArray(int max) // constructor

{

a = new long[max]; // create array

nElems = 0;

}

/////////////////////////////////////////////////////

public int size()

{ return nElems; }

/////////////////////////////////////////////////////

public int find(long searchKey) // 1- I just noticed that this is binary search , what is it and how it works ?

{

int lowerBound = 0; // 2- For what this ?

int upperBound = nElems-1; // 3- For what this , and why nElems-1 , why not +1 ?

int curIn;

while(true)

{

curIn = (lowerBound + upperBound ) / 2; // 4- Why this sentence ?

if(a[curIn]==searchKey) // 5- what does it do ?

return curIn; // found it

else if(lowerBound > upperBound) // 6- why lower > upper ?

return nElems; // can

Explanation / Answer

First off thank you for using a external source, i hate reading a wall of text that is supposed to be a program and has 0 formatting and not readable with that said http://codepad.org/QuvrV7Sm upperBound) // 6- why lower > upper ? //This is for our escape case when we do not find the value, on our last comparison, we will have //lowerBound=upperBound, so when we go into the else, if our a[curIn]upperBound. //Else we would decrease our upper bound by one and again be making our lowerBound>upperBound. return nElems; // can't find it else // divide range { if(a[curIn]
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote