Question 1
EasyWhat is the worst-case time complexity of binary search on a sorted array of n elements?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the worst-case time complexity of binary search on a sorted array of n elements?
O(1)
O(log n)
O(n)
O(n log n)
Answer: B
Each comparison halves the search range, so at most comparisons are needed: .
What is the time complexity of accessing an array element by its index?
O(log n)
O(1)
O(n)
O(n²)
Answer: B
The address is computed directly as base + index × element size, so access takes constant time.
What is the time complexity of linear search in an array of n elements (worst case)?
O(log n)
O(1)
O(n log n)
O(n)
Answer: D
In the worst case every element must be checked.
Which of these grows the fastest as n increases?
O(n³)
O(2ⁿ)
O(n²)
O(n log n)
Answer: B
Exponential growth eventually beats any polynomial: 2ⁿ > n³ for n ≥ 10.
What does Big-O notation describe?
The exact running time in seconds
The lower bound only
An upper bound on how an algorithm's cost grows with input size
The amount of code
Answer: C
Big-O describes growth rate, ignoring constant factors and lower-order terms.
What is the time complexity of two nested loops, each running n times?
O(n)
O(log n)
O(n²)
O(2n)
Answer: C
The inner loop runs n times for each of the n outer iterations: n × n operations.
Simplify O(3n² + 5n + 100).
O(3n²)
O(n² + n)
O(n²)
O(100)
Answer: C
Drop constant factors and lower-order terms; the n² term dominates.
Which complexity describes an algorithm that halves the problem size at every step?
O(n²)
O(log n)
O(1)
O(n)
Answer: B
Halving n repeatedly reaches 1 after about log₂ n steps.
What is the time complexity of a single loop that runs n times and does constant work in each pass?
O(1)
O(log n)
O(n²)
O(n)
Answer: D
The work grows in direct proportion to n.
What is O(1) time called?
Quadratic time
Linear time
Constant time
Logarithmic time
Answer: C
The running time does not depend on the input size.