What is the time complexity of binary search on a sorted array of n elements?
Solution
Each step halves the search range.
20 technical questions of moderate difficulty, as asked in campus placement and company tests. Each has a short explanation.
What is the time complexity of binary search on a sorted array of n elements?
Each step halves the search range.
What is the worst-case time complexity of quicksort?
With poor pivots (for example, an already sorted array with the first element as pivot), quicksort takes O(n²).
What is the time complexity of merge sort in all cases?
Merge sort always splits in half and merges in linear time.
Which sorting algorithm is stable and takes O(n log n) time in the worst case?
Merge sort is stable with guaranteed O(n log n); heap sort and quicksort are not stable.
What is the best-case time complexity of bubble sort with an early-exit check?
On an already sorted array, one pass with no swaps ends the algorithm.
Which algorithm finds the shortest paths from one source in a graph with non-negative edge weights?
Dijkstra's algorithm computes single-source shortest paths when weights are non-negative.
Which algorithm can handle negative edge weights when finding single-source shortest paths?
Bellman-Ford works with negative weights and can detect negative cycles.
Kruskal's and Prim's algorithms are used to find:
Both build a minimum spanning tree of a weighted graph.
Which design technique solves problems by storing the results of overlapping subproblems?
Dynamic programming saves subproblem results to avoid recomputation.
Merge sort is an example of which design technique?
It divides the array, sorts halves and combines them.
What is the time complexity of the naive recursive Fibonacci function?
Each call makes two more calls, giving exponential growth.
How many comparisons does linear search need in the worst case for n elements?
In the worst case, every element is checked.
Topological sorting is possible only for:
A cycle makes a valid ordering impossible.
The 0/1 knapsack problem is typically solved optimally using:
The greedy approach works only for the fractional knapsack; 0/1 needs dynamic programming.
What is the space complexity of merge sort on an array?
Merging needs an auxiliary array of size n.
Which of these grows the fastest as n increases?
Exponential growth eventually exceeds any polynomial.
Using binary search on a sorted array of 1024 elements, what is the maximum number of comparisons needed?
⌊log₂ 1024⌋ + 1 = 10 + 1 = 11 comparisons in the worst case.
Which sorting algorithm repeatedly selects the smallest remaining element and places it next?
Selection sort selects the minimum of the unsorted part in each pass.
Insertion sort performs best when the input is:
On nearly sorted data, few shifts are needed, giving close to O(n).
The N-Queens problem is commonly solved using:
Queens are placed one by one, and the algorithm backtracks when a placement fails.
Want guided preparation? Placement Papers Prep courses by Dr. Kiran Derle, with video lessons and full-length mocks.
See placement courses ↗