This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1Which of the following is NOT a step in the Divide and Conquer algorithm?
Option D
A Divide and Conquer algorithm are a problem-solving technique where a big problem is broken into smaller ones, solved individually, and then combined to produce the final answer. This method is used in algorithms like Merge Sort, Quick Sort, and Binary Search. The Divide and Conquer approach follow three main steps:
Q: 2Which of the following highly uses the concept of an array?
Option C
Spatial Locality is a principle of memory access that states if a memory location is accessed, nearby memory locations are likely to be accessed soon. Since arrays store data in contiguous memory locations, accessing elements sequentially benefits heavily from spatial locality. Thus, arrays highly utilize this concept.
Q: 3Which of the following best describes memorization in dynamic programming?
Option A
Memorization is a key technique used in dynamic programming to improve efficiency by:
In other word, instead of recalculating the result every time, we "memorize" (store) it — typically using an array, map, or hash table.
Q: 4Which of the following statement is false?
Option D
A data structure is indeed a particular way of organizing and storing data so that it can be accessed and modified efficiently. This is true.
Subtraction of two pointers gives the difference in terms of number of elements (blocks) between them, not bytes. This is true.
A function is a block of statements used to perform a specific task. This is true.
Since all the given statements (A), (B), and (C) are true, there is no false statement among them.
Q: 5Which of the following is NOT and NP-Complete problem?
Option C
NP-Complete problems are a class of computational problems that are considered difficult because, while a proposed solution can be verified quickly (in polynomial time), there is no known algorithm that can solve all instances of the problem efficiently. Examples include the Traveling Salesman Problem (TSP), which involves finding the shortest possible route visiting all cities, and the Boolean Satisfiability Problem (SAT), which asks whether a boolean formula can be satisfied.
The Shortest Path Problem, which finds the minimum path between nodes in a graph, is not NP-Complete, because it can be solved efficiently in polynomial time using algorithms like Dijkstra’s or Bellman-Ford.
Q: 6The output of lexical analysis is a
Option D
The process of converting a high-level program into machine code is done in multiple phases of a compiler. Each phase performs a specific task to transform the source code step by step into machine code.
1) Lexical Analysis.
2) Syntax Analysis or Parsing.
3) Semantic Analysis.
4) Intermediate Code Generation.
5) Code Optimization.
6) Code Generation.
In the compilation process, Lexical Analysis is the first phase of a compiler. It takes the source code as input and breaks it into smaller units called tokens such as keywords, identifiers, operators, and constants.
The output of lexical analysis is therefore a stream or set of tokens, which is then passed to the next phase Syntax Analysis.
| Phase | Input | Output | Description |
|---|---|---|---|
| Lexical Analysis | Source Code | Set of Tokens | Breaks source code into small units called tokens (keywords, variables, operators). |
| Syntax Analysis | Tokens | Parse Tree | Checks grammar of the program and builds a structured tree representation. |
| Semantic Analysis | Parse Tree | Annotated Parse Tree | Checks meaning (type checking, variable declaration, etc.). |
| Intermediate Code Generation | Annotated Parse Tree | Intermediate Code | Converts program into a machine-independent intermediate form. |
| Code Optimization | Intermediate Code | Optimized Code | Improves code to make it faster and efficient. |
| Code Generation | Optimized Code | Target/Object Code | Converts optimized code into machine (binary) code for execution. |
Q: 7Which of the following is true about Greedy algorithm?
Option B
A Greedy Algorithm is a problem-solving technique in which the algorithm makes the best possible choice at the current step, without considering future consequences.
The main idea is to select the locally optimal solution at each stage with the hope that these choices will lead to a globally optimal solution.
Instead of exploring all possible solutions, the greedy approach selects the best immediate option according to a specific criterion such as minimum cost, maximum profit, or shortest distance.
This behavior distinguishes greedy algorithms from Dynamic Programming and Backtracking.
Q: 8Consider the following statements and select the correct option:
(I) Last In First Out (LIFO) type of computations are efficiently supported by QUEUE.
(II) First In First Out (FIFO) type of computations are efficiently supported by STACK.
Option D
A Stack follows the LIFO (Last In First Out) principle. The element inserted last is removed first. Typical operations are Push and Pop.
A Queue follows the FIFO (First In First Out) principle. The element inserted first is removed first. Typical operations are Enqueue and Dequeue.
Q: 9Which of the following is not a NP complete problem?
Option D
NP-Complete problems are computational problems that are difficult to solve efficiently.
Clique Problem, Hamiltonian Cycle Problem, and Travelling Salesman Problem are NP-Complete problems.
The Shortest Path Problem is not NP-Complete because efficient algorithms like Dijkstra’s Algorithm can solve it in Polynomial Time.
Q: 10
Match List-I (Solution Approach) with List-II (Problems) and select the correct answer:
| List-I | List-II |
|---|---|
| A. Divide and Conquer Approach | 1. Graph Coloring |
| B. Dynamic Programming | 2. 0/1 Knapsack |
| C. Greedy Approach | 3. Strassen Matrix Multiplication |
| D. Backtracking | 4. Huffman Encoding |
Option C
The Divide and Conquer Approach solves problems by dividing them into smaller independent subproblems and combining their solutions, which is exactly how Strassen Matrix Multiplication reduces matrix multiplication complexity.
Strassen’s Algorithm divides matrices into smaller sub-matrices, solves them recursively, and then combines the results.
Dynamic Programming is used when a problem has overlapping subproblems and optimal substructure. Dynamic programming stores intermediate results to avoid repeated computation. The 0/1 Knapsack problem has overlapping subproblems and optimal substructure.
The Greedy Approach works by making locally optimal choices, and Huffman Encoding uses this idea by repeatedly choosing the least frequent symbols to build an optimal coding tree.
The Backtracking is used to explore all possible solutions by trying choices and undoing them if they lead to failure. Graph Coloring tries different color assignments and backtracks whenever a conflict occurs, making backtracking the suitable approach.
Q: 11The knapsack problem where the objective function is to minimize the profit is-
Option D
The 0/1 Knapsack problem is a classic combinatorial optimization problem where each item must be either included or excluded from the knapsack. In this version, the objective is to minimize the profit (or cost), rather than maximize it. Simple greedy methods are not suitable here because they do not always guarantee an optimal solution for 0/1 decisions.
To handle minimization effectively, the Branch & Bound (0/1) technique is used. This method systematically explores all possible combinations of items while using bounds to prune suboptimal branches, which reduces unnecessary computations. While dynamic programming or backtracking can also solve the problem.
You have reached the end of this topic. Continue learning with the next topic below.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.