19. Binary Search Implementation Below is an implementation of binary search, but the implementation contains an error. What is the error? 251 - def binary_search(array, target): 252 253 254...


19. Binary Search Implementation<br>Below is an implementation of binary search, but the implementation contains an error. What is the error?<br>251 - def binary_search(array, target):<br>252<br>253<br>254<br>left,right = 0,len(array)-1<br>while left <= right:<br>mid = left + ((right - left) // 2)<br>if target == array[mid]:<br>255<br>256<br>return mid<br>elif target < array[mid]:<br>left = mid + 1<br>else:<br>right = mid - 1<br>257<br>258<br>259<br>|260<br>261<br>return None<br>Pick ONE option<br>Line 253 should be change to: while left < right<br>Lines 258 and 260 should be switched<br>O right should be initialized to len(array) instead of len(array)-1<br>Nothing is incorrect<br>Clear Selection<br>

Extracted text: 19. Binary Search Implementation Below is an implementation of binary search, but the implementation contains an error. What is the error? 251 - def binary_search(array, target): 252 253 254 left,right = 0,len(array)-1 while left <= right:="" mid="left" +="" ((right="" -="" left)="" 2)="" if="" target="=" array[mid]:="" 255="" 256="" return="" mid="" elif="" target="">< array[mid]:="" left="mid" +="" 1="" else:="" right="mid" -="" 1="" 257="" 258="" 259="" |260="" 261="" return="" none="" pick="" one="" option="" line="" 253="" should="" be="" change="" to:="" while="" left="">< right="" lines="" 258="" and="" 260="" should="" be="" switched="" o="" right="" should="" be="" initialized="" to="" len(array)="" instead="" of="" len(array)-1="" nothing="" is="" incorrect="" clear="">

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here