If a is an array that contains the values from 1 to 100 in order. How may comparisons are done to search for 50 using the binary search algorithm ? hint: 50 is at index 50 in the array. Binary search...


If a is an array that contains the values from 1 to 100 in order. How may comparisons<br>are done to search for 50 using the binary search algorithm ?<br>hint: 50 is at index 50 in the array.<br>Binary search code:<br>int [] a = new int[100];<br>for (int i<br>a[i]<br>}<br>int key<br>7<br>0; i < a.length; i++) {<br>i+1;<br>8<br>9.<br>10<br>50;<br>boolean found =<br>11<br>%3D<br>12<br>false;<br>int low<br>0;<br>a.length<br>while(low <= high && !found){<br>int mid = (1low + high) / 2;<br>a[mid])<br>13<br>14<br>int high<br>1;<br>15<br>16<br>17<br>if(key<br>==<br>18<br>found<br>true;<br>else if(key > a[mid])<br>low = mid + 1;<br>%3D<br>19<br>20<br>21<br>else<br>22<br>high<br>mid<br>1;<br>23<br>

Extracted text: If a is an array that contains the values from 1 to 100 in order. How may comparisons are done to search for 50 using the binary search algorithm ? hint: 50 is at index 50 in the array. Binary search code: int [] a = new int[100]; for (int i a[i] } int key 7 0; i < a.length;="" i++)="" {="" i+1;="" 8="" 9.="" 10="" 50;="" boolean="" found="11" %3d="" 12="" false;="" int="" low="" 0;="" a.length="" while(low=""><= high="" &&="" !found){="" int="" mid="(1low" +="" high)="" 2;="" a[mid])="" 13="" 14="" int="" high="" 1;="" 15="" 16="" 17="" if(key="=" 18="" found="" true;="" else="" if(key=""> a[mid]) low = mid + 1; %3D 19 20 21 else 22 high mid 1; 23

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here