Comparing Basic Time Complexity
What is the average-case time complexity of Binary Search on a sorted array?
- O(log n)
- O(n^2)
- O(n log n)
- O(n)
- O(1og n)
When to Use Linear Search
Which situation BEST justifies using Linear Search over Binary Search?
- The list is unsorted.
- The list is always sorted.
- The list contains unique elements only.
- The list size is always a power of two.
- The list is sorted in reverse order.
Binary Search Requirements
Which is a NECESSARY requirement for Binary Search to operate correctly?
- The array must be sorted.
- The array must contain only integers.
- The array must have an odd length.
- The array must be cyclic.
- All array elements must be positive.
Comparative Efficiency in Practice
Given a sorted array of 1,000,000 elements, which search algorithm is likely to find an element faster on average?
- Binary Search
- Linnear Search
- Linear Seach
- Lineer Search
- Jump Search
Effect of an Unsorted Array
If a list is NOT sorted, which of the following search algorithms can ALWAYS guarantee to find the target if present?
- Linear Search
- Binary Search
- Binari Search
- Expoential Search
- Jump Sarch
Best Case Scenario
What is the BEST CASE time complexity for Linear Search?
- O(1)
- O(log n)
- O(n)
- O(n log n)
- O(n^2)
Practical Code Comparison
Consider this code snippet: for (int i = 0; i u003C arr.length; i++) { if (arr[i] == target) return i; } What algorithm does it represent?
- Linear Search
- Binary Seach
- Binery Search
- Jump Search
- Exponential Search
Binary Search Midpoint Calculation
In Binary Search, how is the 'mid' index typically calculated to avoid integer overflow?
- mid = low + (high - low) / 2
- mid = (low / 2) + (high / 2)
- mid = low - (high + low) / 2
- mid = high / 2
- mid = (high + low) / 2
Handling Duplicates
If a sorted array contains duplicates, can Binary Search always find the FIRST occurrence of a target value?
- No, standard Binary Search finds an occurrence, not necessarily the first.
- Yes, it always finds the first occurrence.
- No, Binary Search does not work with duplicates.
- Yes, but only if all elements are distinct.
- Yes, if the array is sorted in ascending order only.
Space Complexity Comparison
What is the space complexity for both Linear and Binary Search (using iterative approach)?
- O(1)
- O(n)
- O(log n)
- O(n^2)
- O(0)