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

The code to answer exercise 9.1 is below; however, it is incorrect. Please edit

ID: 3776060 • Letter: T

Question

The code to answer exercise 9.1 is below; however, it is incorrect. Please edit the code so that the value 38 is found in the variable "akey" at index 0.

Sorry incorrect, the value in akey 38 was NOT found in the array at index 0 Return to Exercise Close Window Your Code with color highlights added): index 0; while (index thearray.length()) if (akey thearray[inde break else if a key thearraylindex]) inde 2 index 1 else index 2 index 2; The Instructions: Exercise 9.1 Search ID Binary Tree Array The ID array thearray contains a binary tree with the root at index 0 Write a while loop to search for the value in the variable akey Write an if-else to change the variable index to search the left or right child When the loop completes index must be the slot that equals variable akey Do not declare the variable index, but do initialize and change it during the search. Help: Type this in first, then back up and fill it out: while if else

Explanation / Answer

while(index<arr.length){
if(arr[index]==akey)
System.out.println("akey matched at index "+index);
else{
index=arr.length/2;
if(akey<arr[index] && index !=0){
if(akey==arr[index]){
System.out.println("Element found at index:"+index);
index--;
}
index=arr.length/2;
}
else {
if(akey>arr[index] && index !=arr.length){
if(akey==arr[index]){
System.out.println("Element found at index:"+index);
index++;
}
}
  
}
  
}
  
  
}
  

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