Consider the following code fragment: static int f(int[ ] arr, int x ) { int start = 0; int end - arr.length -13; int mid; while(start x) { end - mid-1; } else { return mid; } } return -1; } Give the...


Consider the following code fragment:<br>static int f(int[ ] arr, int x ) {<br>int start = 0;<br>int end - arr.length -13;<br>int mid;<br>while(start <= end) {<br>mid = start + ((end - start)/2);<br>if(arr[ mid ] < x) {<br>start<br>mid+1;<br>} else if(arr[ mid ] > x) {<br>end - mid-1;<br>} else {<br>return mid;<br>}<br>}<br>return -1;<br>}<br>Give the worst case big-O cost where the length of the array is N.<br>O O(N^2)<br>O (1)<br>O 0(2^N)<br>O O(logN)<br>O(N)<br>

Extracted text: Consider the following code fragment: static int f(int[ ] arr, int x ) { int start = 0; int end - arr.length -13; int mid; while(start <= end)="" {="" mid="start" +="" ((end="" -="" start)/2);="" if(arr[="" mid="" ]="">< x)="" {="" start="" mid+1;="" }="" else="" if(arr[="" mid="" ]=""> x) { end - mid-1; } else { return mid; } } return -1; } Give the worst case big-O cost where the length of the array is N. O O(N^2) O (1) O 0(2^N) O O(logN) O(N)

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here