Skip to main content

10 MCQs related to Code Optimization

10 Multiple Choice Questions (MCQs) related to Code Optimization, useful for UGC NET, SET, and GATE exams:


1. What is the main purpose of code optimization in a compiler?

A) Convert source code to machine code
B) Improve the execution speed and reduce resource usage
C) Detect syntax errors
D) Allocate memory for variables

Explanation:
Code optimization aims to enhance the performance of the compiled code by reducing execution time, memory usage, and power consumption.

Answer: B) Improve the execution speed and reduce resource usage


2. Which of the following is NOT a type of code optimization?

A) Peephole Optimization
B) Loop Optimization
C) Syntax Checking
D) Constant Folding

Explanation:
Syntax Checking is part of syntax analysis, not code optimization.

Answer: C) Syntax Checking


3. Which of the following is an example of local optimization?

A) Loop Unrolling
B) Constant Folding
C) Register Allocation
D) Dead Code Elimination

Explanation:
Local optimization focuses on small portions of code, such as constant folding, which replaces constant expressions with their computed values at compile time.

Answer: B) Constant Folding


4. What does Dead Code Elimination (DCE) do?

A) Removes redundant instructions
B) Eliminates unreachable code that has no effect on program output
C) Removes comments from the code
D) Converts source code into an intermediate representation

Explanation:
Dead Code Elimination removes instructions that are never executed or whose results are never used, improving efficiency.

Answer: B) Eliminates unreachable code that has no effect on program output


5. Which optimization technique reduces the overhead of loop control statements?

A) Loop Unrolling
B) Constant Propagation
C) Common Subexpression Elimination
D) Strength Reduction

Explanation:
Loop Unrolling reduces the number of iterations by expanding the loop body, decreasing branching overhead.

Answer: A) Loop Unrolling


6. What is the purpose of Register Allocation in code optimization?

A) Convert high-level code to low-level code
B) Allocate variables to CPU registers to reduce memory access
C) Remove redundant computations
D) Detect semantic errors

Explanation:
Register allocation assigns frequently used variables to CPU registers, reducing memory access time and improving efficiency.

Answer: B) Allocate variables to CPU registers to reduce memory access


7. Which of the following optimization techniques replaces expensive operations with equivalent but cheaper operations?

A) Peephole Optimization
B) Strength Reduction
C) Inline Expansion
D) Code Hoisting

Explanation:
Strength Reduction replaces expensive operations (e.g., multiplication) with simpler ones (e.g., addition or bit-shifting).

Answer: B) Strength Reduction


8. What does Common Subexpression Elimination (CSE) do?

A) Removes unused variables
B) Identifies and eliminates repeated computations
C) Reduces the number of loops
D) Converts code into an abstract syntax tree

Explanation:
CSE finds repeated expressions in a program and computes them only once, storing the result for reuse.

Answer: B) Identifies and eliminates repeated computations


9. What is Global Optimization in compilers?

A) Optimization applied to a small block of code
B) Optimization applied across the entire program
C) Optimization applied only at the assembly level
D) Syntax analysis improvement

Explanation:
Global optimization analyzes the entire program to apply transformations like loop optimizations and dead code elimination across function boundaries.

Answer: B) Optimization applied across the entire program


10. What is the main goal of Peephole Optimization?

A) Optimize a small set of adjacent instructions
B) Reduce recursion in function calls
C) Improve parsing speed
D) Increase compilation time

Explanation:
Peephole optimization scans small sequences of instructions and replaces them with faster or more efficient alternatives.

Answer: A) Optimize a small set of adjacent instructions

Comments

Popular posts from this blog

Top 5 Safe Chat Apps for Kids with Parental Controls

Now a days kids are growing up with technology at their fingertips. While communication apps help children stay connected with family and friends, safety remains a top concern for parents. Unregulated platforms can expose children to inappropriate content, online predators, and cyberbullying. That’s why choosing a kid-friendly chat app with parental controls is essential. To help parents find the best options, we’ve compiled a list of the top five safest chat apps for kids that offer safe and controlled environment. 1. Messenger Kids (By Meta) Best for: Safe video calls and text messaging with parental supervision Features: Parents approve all contacts No ads or in-app purchases Fun filters, stickers, and games Monitored messaging and activity reports Why It’s Safe: Messenger Kids is designed for children under 13 and requires parental approval for every contact. Parents can monitor chats and control screen time through the Parent Dashboard. Download Messenger Kids 2...

AI from Class 3: India’s Big Leap into the Future of Learning

Imagine that, it's a morning in 2026. In a classroom, a teacher holds up a tablet. Instead of reciting multiplication tables, a group of eight-year-olds watches a tiny animation explaining how computers “learn” from patterns. A curious hand shoots up. “Ma’am, does that mean my phone is smarter than me?” The class bursts into laughter, but the question lingers. That, in essence, is the beginning of India’s new chapter — where Artificial Intelligence is no longer a distant, sci-fi term, but a part of early education. The Turning Point The Central Board of Secondary Education (CBSE) has drafted a plan to introduce AI as a subject from Class 3 to Class 12 , a first in the country’s education history. The proposal, now with NCERT for expert review, aims to roll out by April 2026 . If all goes to plan, teacher training will begin next year, resource books and digital tools will follow, and by the time the next generation steps into school, “AI” will sit alongside English, Science,...

10 Distance Vector and Link-State Routing MCQ

  10 multiple-choice questions  on  Distance Vector and Link-State Routing with explanations, useful for  UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Basic Concept of Distance Vector Routing Q1: In a distance vector routing protocol, how do routers share routing information? A) By flooding the entire network with routing updates B) By periodically exchanging routing tables with their immediate neighbors C) By using a link-state database to determine the shortest path D) By dynamically updating paths based on link failure reports Answer: B) By periodically exchanging routing tables with their immediate neighbors Explanation: In Distance Vector Routing, routers share their routing tables with neighbors at regular intervals, leading to a simple but slow convergence mechanism. Question 2: Example of Distance Vector Routing Protocol Q2: Which of the following is an example of a Distance Vector routing protocol? A) OSPF ...