In terms of space complexity, how does the iterative binary search compare to the recursive one?
Explanation:
Recursive calls in binary search incur function call overhead, potentially leading to higher space usage than an iterative approach.
In what scenario would linear search be more suitable than binary search?
Explanation:
For very small datasets or unsorted data, the overhead of sorting for binary search might outweigh its benefits. Linear search, while generally slower, can be more efficient in these specific cases.
What is the time complexity of Binary Search in the best-case scenario?
Explanation:
In the best case, the target element is found in the middle of the array on the first comparison, resulting in constant time.
You have an unsorted array, and you need to find a specific value. Is it more efficient to sort the array and then use binary search, or to directly apply linear search?
Explanation:
Sorting an array itself generally has a time complexity of O(n log n). If you only need to find one value, linear search's O(n) complexity is more efficient than sorting followed by binary search.
In binary search, what happens if the target value is less than the middle element of the current search interval?
Explanation:
Since the array is sorted, if the target is less than the middle, it must reside in the left portion.
What is the time complexity of Binary Search in the worst-case scenario?
Explanation:
Binary Search halves the search space in each step, leading to a logarithmic time complexity. In the worst case, we perform log n comparisons.
What happens if the target element is not present in the array during Binary Search?
Explanation:
By convention, Binary Search returns -1 to indicate that the target element was not found in the array.
How does Binary Search handle duplicate elements in a sorted array?
Explanation:
The standard Binary Search algorithm does not guarantee which occurrence's index will be returned if duplicates exist.
What value does binary search return if the target element is not present in the sorted array?
Explanation:
There is no single standard. Some implementations return -1, others might return the index where the element would be if inserted, and others might use a different convention.
Which of the following best describes the advantage of binary search over linear search?
Explanation:
The primary advantage of binary search is its efficiency. It outperforms linear search in the average and worst-case scenarios due to its logarithmic time complexity, especially for larger datasets.
What is the key characteristic of an array that makes Binary Search applicable?
Explanation:
Binary Search fundamentally relies on the array being sorted. It repeatedly divides the search interval in half, which is only efficient and correct if the array is sorted.
Which of the following is a prerequisite for using binary search on a dataset?
Explanation:
Binary search relies on the data being sorted to repeatedly narrow down the search interval. Without a sorted dataset, you cannot effectively determine which half to discard in each step.
What is the base case in a recursive implementation of binary search?
Explanation:
The base case signals the end of recursion. In binary search, it occurs when either the target is found or the interval is empty, indicating the target's absence.
Which of the following best describes the time complexity of binary search in the average case?
Explanation:
Binary search halves the search space with each step, resulting in a logarithmic time complexity.
In the context of Binary Search, what is the problem with searching in an infinitely sized array?
Explanation:
Standard Binary Search requires a defined search space with a start and an end. Infinite arrays lack this defined end, making the classic algorithm inapplicable.