Searching Algorithms: Binary Search - Implementations in C++ - Competitive Exam Level

Download Q&A
Q. How does binary search determine which half of the array to search next?
  • A. By comparing the middle element with the target
  • B. By checking the length of the array
  • C. By using a random index
  • D. By iterating through the array
Q. In which scenario can binary search be applied?
  • A. Unsorted array
  • B. Sorted array
  • C. Linked list
  • D. Stack
Q. What is the space complexity of binary search when implemented iteratively?
  • A. O(n)
  • B. O(log n)
  • C. O(1)
  • D. O(n log n)
Q. What is the worst-case scenario for the number of comparisons in binary search?
  • A. n
  • B. log n
  • C. n log n
  • D. 1
Q. What will be the return value of binary search if the element is not found?
  • A. -1
  • B. 0
  • C. 1
  • D. n
Q. Which of the following C++ functions correctly implements binary search?
  • A. int binarySearch(int arr[], int l, int r, int x)
  • B. void binarySearch(int arr[], int x)
  • C. int binarySearch(int arr[], int x)
  • D. bool binarySearch(int arr[], int l, int r)
Q. Which of the following is a requirement for binary search to work?
  • A. The array must be sorted
  • B. The array must be of even length
  • C. The array must contain unique elements
  • D. The array must be in ascending order
Q. Which of the following statements about binary search is false?
  • A. It can be implemented recursively
  • B. It requires a sorted array
  • C. It can be used on linked lists
  • D. It is faster than linear search
Showing 1 to 8 of 8 (1 Pages)
Soulshift Feedback ×

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

Not likely Very likely