Searching Algorithms: Binary Search - Implementations in Python - Problem Set

Download Q&A
Q. What will be the result of binary search if the target value is not present in the array?
  • A. Returns the index of the closest value
  • B. Returns -1
  • C. Returns the index of the last element
  • D. Returns the index of the first element
Q. Which of the following is a valid implementation of binary search in Python?
  • A. def binary_search(arr, target): ...
  • B. def binary_search(arr, target): for i in arr: if i == target: return i
  • C. def binary_search(arr, target): while arr: ...
  • D. def binary_search(arr, target): return arr.index(target)
Showing 1 to 2 of 2 (1 Pages)
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely