Searching Algorithms: Binary Search - Implementations in Python

Download Q&A
Q. In Python, which of the following is a correct implementation of binary search?
  • A. def binary_search(arr, x): ...
  • B. def binary_search(arr, x): return arr.index(x)
  • C. def binary_search(arr, x): for i in arr: if i == x: return i
  • D. def binary_search(arr, x): while arr: ...
Q. What will be the output of binary search if the target element is not present in the array?
  • A. Index of the closest element
  • B. -1
  • C. 0
  • D. Length of the array
Q. Which of the following best describes the divide-and-conquer approach used in binary search?
  • A. Solving a problem by breaking it down into smaller subproblems
  • B. Using a single loop to iterate through elements
  • C. Recursively calling the same function without any condition
  • D. Sorting the array before searching
Showing 1 to 3 of 3 (1 Pages)
Soulshift Feedback ×

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

Not likely Very likely