Algorithms questions and answers
Complexity, sorting, searching, recursion and DP. Practise algorithms questions from the technical & programming section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.
Sample algorithms questions with worked answers
Question 1
What is the worst-case time complexity of binary search on a sorted array of n elements?
- O(n)
- O(log n)
- O(n log n)
- O(1)
Answer: B. O(log n)
Explanation: Each comparison halves the remaining search range, so at most about log2(n) + 1 comparisons are needed.
Question 2
What is the solution of the recurrence T(n) = 2T(n/2) + n, with T(1) = 1?
- O(n)
- O(n²)
- O(log n)
- O(n log n)
Answer: D. O(n log n)
Explanation: There are log2 n levels of recursion and each level does a total of n work, giving O(n log n). This is the recurrence of merge sort.
Question 3
What is the length of the Longest Common Subsequence (LCS) of the strings "ABCBDAB" and "BDCABA"?
- 3
- 4
- 5
- 6
Answer: B. 4
Explanation: Filling the standard LCS DP table gives 4; one such subsequence is "BCBA". No common subsequence of length 5 exists.
All 30 algorithms questions with answers
- What is the worst-case time complexity of binary search on a sorted array of n…
- Which of the following sorting algorithms is NOT comparison-based?
- Bubble sort is implemented with a flag that stops the algorithm when a pass…
- What is the maximum number of probes (middle-element checks) binary search…
- Merge sort is an example of which algorithm design technique?
- What is the solution of the recurrence T(n) = 2T(n/2) + n, with T(1) = 1?
- What is the maximum number of swaps selection sort performs on an array of n…
- Quick sort always picks the last element as the pivot. For which input does it…
- What does the following function return for f(4096)?
- Coins of value ₹1, ₹3 and ₹4 are available in unlimited supply. A greedy…
- Insertion sort is applied to [5, 2, 4, 6, 1, 3]. What does the array look like…
- What is the length of the Longest Common Subsequence (LCS) of the strings…
- A 0/1 knapsack has capacity 7 kg. The items (weight, value) are: (1 kg, ₹1)…
- For the naive recursive Fibonacci function below, how many times is fib called…
- Using the Master theorem, what is the solution of T(n) = 3T(n/2) + n?
- What is the best-case time complexity of linear search on an array of n…
- Which of the following sorting algorithms is stable in its standard…
- Which algorithm finds single-source shortest paths correctly even when some…
- What is the worst-case time complexity of merge sort on n elements?
- What is the time complexity of finding the largest element in an unsorted…
- Bubble sort is applied to the array [4, 1, 3, 2] in ascending order. What does…
- Two sorted lists with 6 and 9 elements are merged into one sorted list using…
- An undirected weighted graph has the edges A-B 4, A-C 1, B-C 2, B-D 5, C-D 8…
- What is the solution of the recurrence T(n) = T(n - 1) + n, with T(1) = 1?
- Coins of ₹2, ₹3 and ₹5 are available in unlimited supply. In how many…
- Selection sort (ascending) is applied to [29, 10, 14, 37, 13]. In each pass…
- What is the edit distance (minimum number of single-character insertions…
- Four matrices with dimensions 5×10, 10×3, 3×12 and 12×5 are multiplied as a…
- Lomuto partition with the last element as the pivot is applied once to [7, 2…
- What is the length of the longest strictly increasing subsequence of [3, 10…
Algorithms: common questions
What are algorithms questions?
Complexity, sorting, searching, recursion and DP. They appear in the technical & programming section of many placement tests.
Where can I practise algorithms questions with answers for free?
Right here on LogicWiz Exams. Every algorithms question has a worked explanation after you answer. Practice is free and needs no sign-up.
How should I practise algorithms?
Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.
Start practising
On this page you can start a fresh set of algorithms questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Technical & Programming practice.
More technical & programming topics
- Pseudo-code: Trace loops, recursion and bitwise logic.
- C Programming: Output prediction, pointers and operators.
- Java: OOP, strings, collections and exceptions.
- Python: Data types, comprehensions and mutability.
- Data Structures: Arrays, stacks, queues, trees, graphs and hashing.
- Object-Oriented Programming: Encapsulation, inheritance, polymorphism, abstraction.
- DBMS: Keys, normalisation, transactions and indexing.
- SQL: Joins, grouping, subqueries and query output.
- Operating Systems: Processes, scheduling, memory and deadlocks.
- Computer Networks: OSI/TCP-IP, protocols, addressing and ports.
- Software Engineering: SDLC, testing, agile and version control.
- Cloud & DevOps: Service models, containers, CI/CD and Linux.
- GenAI Basics: LLMs, tokens, prompting, embeddings and RAG.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep