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...

10 Routing Protocol MCQ

10 multiple-choice questions on Routing protocol s  with explanations, useful for UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Purpose of Routing Protocols Q1: What is the primary purpose of a routing protocol? A) To assign IP addresses to devices B) To determine the best path for data packets to reach their destination C) To encrypt data during transmission D) To physically connect different networks Answer: B) To determine the best path for data packets to reach their destination Explanation: Routing protocols help routers determine the most efficient path for data transmission across a network, ensuring fast and reliable communication. Question 2: Classification of Routing Protocols Q2: Routing protocols can be broadly classified into which two main categories? A) TCP and UDP B) Distance Vector and Link-State C) IPv4 and IPv6 D) Static and Dynamic Answer: B) Distance Vector and Link-State Explanation: Routing prot...

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 ...