Linear Search Complexity
What is the worst-case time complexity of a linear search algorithm?
- O(log n)
- O(1)
- O(n log n)
- O(n)
- O(n^2)
Binary Search Requirement
What crucial property must an array possess for binary search to function correctly?
- It must be sorted.
- It must contain only unique elements.
- It must be dynamically allocated.
- It must be a linked list.
- It must be of a fixed size.
Binary Search Complexity
What is the time complexity of a binary search in the best-case scenario?
- O(n)
- O(log n)
- O(n log n)
- O(1)
- O(n^2)
Linear Search vs. Binary Search
For searching an unsorted array, which search algorithm is generally more efficient?
- Binary search
- Linear search
- Both are equally efficient
- Depends on the size of the array
- Ternary Search
Binary Search Iterations
Approximately how many iterations would binary search take to find an element in a sorted array of 1024 elements in the worst case?
- 10
- 20
- 512
- 1024
- 1000
Linear Search on a Sorted Array
If a linear search is performed on a sorted array, can its best-case time complexity ever be better than O(n)?
- No, it will always be O(n)
- Yes, it can be O(1)
- It depends on the specific array
- Yes, it can be O(log n)
- Yes, it can be O(n/2)
Complexity comparison
Which search algorithm performs faster on average for very large, sorted datasets?
- Linear search
- Binary search
- Sequential Search
- They perform equally
- Depends on the processor speed
When Binary Search Fails
Under what condition will binary search fail to find the target value in a sorted array?
- If the array is empty.
- If the target value is at the last index.
- If the array contains duplicate values.
- If the array is too large.
- Binary Search never fails
Time Complexity Linear Search Best Case
What is the best case time complexity for linear serach?
- O(n)
- O(log n)
- O(1)
- O(n/2)
- O(n^2)
When to use Linear Search
In which scenario is a linear search generally preferred over a binary search?
- When searching a small, unsorted list
- When searching a large, sorted array
- Wen the data size is too large
- Whenever Speed is important
- When memory is limited