Binary search MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is the primary purpose of the Binary Search algorithm?
A) To find the maximum element in an array
B) To search for a specific element in a sorted array
C) To sort an array
D) To merge two arrays
Answer: B) To search for a specific element in a sorted array

What is the time complexity of Binary Search in the worst case?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: C) O(log n)

Which of the following conditions must be met for Binary Search to work?
A) The array must be unsorted
B) The array must be sorted
C) The array must contain unique elements
D) The array must be in ascending order only
Answer: B) The array must be sorted

What is the best-case time complexity for Binary Search?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)

Which algorithm would typically be slower than Binary Search for large datasets?
A) Linear Search
B) Quick Sort
C) Merge Sort
D) Heap Sort
Answer: A) Linear Search

How does Binary Search determine the next step in the search process?
A) By dividing the array into halves
B) By sorting the array
C) By searching in a linear manner
D) By checking every element
Answer: A) By dividing the array into halves

In Binary Search, what happens if the middle element is less than the target?
A) Search continues in the left half
B) Search continues in the right half
C) Search ends
D) An error is thrown
Answer: B) Search continues in the right half

What is the space complexity of Binary Search when implemented iteratively?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)

What is the main advantage of Binary Search over Linear Search?
A) It requires less memory.
B) It works on unsorted arrays.
C) It is faster for large datasets.
D) It is easier to implement.
Answer: C) It is faster for large datasets.

How many comparisons can Binary Search make in the worst case for an array of size n?
A) n
B) log n
C) n/2
D) n^2
Answer: B) log n

Which of the following is a disadvantage of Binary Search?
A) Requires a sorted array
B) More complex than Linear Search
C) Both A and B
D) None of the above
Answer: C) Both A and B

What is the result of a Binary Search if the target element is found?
A) The index of the element
B) The value of the element
C) An error message
D) The middle index of the array
Answer: A) The index of the element

How is the middle index calculated in Binary Search?
A) (low + high) / 2
B) (low + high)
C) (high – low) / 2
D) (low + high + 1) / 2
Answer: A) (low + high) / 2

What will Binary Search return if the target element is not found?
A) 0
B) -1
C) The index of the last element
D) An error message
Answer: B) -1

In which scenario is Binary Search most effective?
A) When the data is unsorted
B) When the dataset is small
C) When searching in large, sorted datasets
D) When looking for multiple occurrences
Answer: C) When searching in large, sorted datasets

What happens if the array is empty when performing Binary Search?
A) It returns the first index.
B) It returns -1.
C) It throws an exception.
D) It searches indefinitely.
Answer: B) It returns -1.

What type of search does Binary Search use?
A) Iterative
B) Recursive
C) Both iterative and recursive
D) None of the above
Answer: C) Both iterative and recursive

How does Binary Search perform when dealing with duplicates?
A) It finds the first occurrence only.
B) It finds all occurrences.
C) It cannot handle duplicates.
D) It finds the last occurrence only.
Answer: A) It finds the first occurrence only.

What is the typical use case for Binary Search?
A) Searching for an element in a large unsorted list
B) Searching for an element in a sorted array
C) Sorting a list
D) Merging two sorted lists
Answer: B) Searching for an element in a sorted array

Which of the following is true about Binary Search?
A) It can only be implemented recursively.
B) It can be implemented with a linked list.
C) It requires random access to the array elements.
D) It is always faster than Linear Search.
Answer: C) It requires random access to the array elements.

What is the worst-case scenario for Binary Search?
A) The target is the first element.
B) The target is the last element.
C) The target is not in the array.
D) The target is in the middle.
Answer: C) The target is not in the array.

Which condition indicates that the search space has been exhausted in Binary Search?
A) low > high
B) low == high
C) low == mid
D) high == mid
Answer: A) low > high

What is a practical application of Binary Search?
A) Searching in a phone book
B) Finding a book in a library
C) Checking availability in an inventory
D) All of the above
Answer: D) All of the above

What modification can be made to Binary Search to find the first occurrence of a target?
A) Change the middle calculation.
B) Continue searching in the left half even after finding the target.
C) Ignore duplicates.
D) Start from the end of the array.
Answer: B) Continue searching in the left half even after finding the target.

Which of the following is not a prerequisite for Binary Search?
A) The data must be sorted.
B) The data must be in an array.
C) The data must support random access.
D) The data can be of any type.
Answer: B) The data must be in an array.

What can be concluded about the efficiency of Binary Search compared to Linear Search?
A) Binary Search is always more efficient.
B) Binary Search is more efficient for larger datasets.
C) Both have the same efficiency.
D) Linear Search is more efficient for sorted data.
Answer: B) Binary Search is more efficient for larger datasets.

How does the performance of Binary Search degrade?
A) With smaller datasets
B) With sorted arrays
C) With larger datasets
D) With unsorted arrays
Answer: D) With unsorted arrays

What must be true about the elements in the array for Binary Search to function correctly?
A) They must be unique.
B) They must be in ascending order.
C) They can be in any order.
D) They must be in descending order.
Answer: B) They must be in ascending order.

What is the primary disadvantage of Binary Search?
A) It requires a sorted array.
B) It is slower than Linear Search.
C) It consumes more memory.
D) It can only find unique elements.
Answer: A) It requires a sorted array.

Which of the following statements about Binary Search is false?
A) It can be implemented recursively.
B) It can be used on linked lists.
C) It has a logarithmic time complexity.
D) It works only on sorted arrays.
Answer: B) It can be used on linked lists.

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs