You need to choose an algorithm for a real-time system with strict timing constraints. Algorithm X has a time complexity of O(n log n) in the worst case and Θ(1) in the best case. Algorithm Y has a time complexity of Θ(n) in all cases. Which algorithm is a safer choice and why?
Algorithm Y, because its time complexity is consistent and predictable.
Both algorithms are equally suitable for a real-time system.
Algorithm X, because its best-case complexity is excellent.
Neither algorithm is suitable for a real-time system.
Which of the following operations generally exhibits O(log n) time complexity in a balanced binary search tree?
Inserting a new element
Calculating the height of the tree
Printing all elements in sorted order
Finding the minimum element
You are designing a system to handle real-time stock market data. Which of the following time complexities would be LEAST desirable for an algorithm processing incoming price updates?
O(log n)
O(n)
O(2^n)
O(1)
Which of the following notations provides the tightest possible bound on the growth rate of an algorithm's running time?
Big-O (O)
Big-Theta (Θ)
Big-Omega (Ω)
Little-o (o)
Which notation is most appropriate to describe the best-case time complexity of an algorithm where the input size doesn't affect the running time?
Little-omega (ω)
A randomized algorithm has a worst-case running time of O(n^2), but its expected running time is O(n log n). What does this imply about the algorithm's performance?
The algorithm always runs in O(n log n) time.
The algorithm is unsuitable for practical use due to its unpredictable running time.
The algorithm's running time is independent of the input.
On average, the algorithm performs better than its worst-case bound.
Which statement about benchmarking is TRUE?
Benchmarking is primarily used for comparing the theoretical time complexity of different algorithms.
Benchmarking focuses on measuring the execution time of an algorithm in a controlled environment.
Benchmarking results are always generalizable across different hardware and software environments.
Benchmarking is only useful for large-scale applications and not for smaller projects.
You have two algorithms, A and B, for the same problem. A has a time complexity of O(n log n) and Ω(n), while B has a time complexity of O(n^2) and Ω(log n). Which of the following statements is always true?
Algorithm A is faster than Algorithm B for all input sizes.
We cannot definitively compare the performance of the two algorithms based on the given information.
Algorithm A is faster than Algorithm B for sufficiently large input sizes.
Algorithm B is faster than Algorithm A for all input sizes.
What is the time complexity of the following code snippet?
def mystery(n): if n <= 1: return 1 return mystery(n-1) + mystery(n-2)
O(n log n)
Which of the following is the LEAST reliable indicator of an algorithm's real-world performance?
Worst-case time complexity
Profiling results on a representative dataset
Average-case time complexity
Benchmarking results on different hardware configurations