0% found this document useful (0 votes)
5 views

Compiler-Design

The document contains solutions to practice questions from a textbook on Compiler Design, focusing on topics such as lexical analysis, parsing techniques, and grammar properties. It provides answers along with brief explanations for each question, covering various aspects of compiler design. The content is structured into chapters with multiple-choice questions and detailed solutions.

Uploaded by

Sk Rahelasamreen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Compiler-Design

The document contains solutions to practice questions from a textbook on Compiler Design, focusing on topics such as lexical analysis, parsing techniques, and grammar properties. It provides answers along with brief explanations for each question, covering various aspects of compiler design. The content is structured into chapters with multiple-choice questions and detailed solutions.

Uploaded by

Sk Rahelasamreen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Compiler Design

(Solutions for Text Book Practice Questions)

Chapter 07. Ans: (b) & (c)


Lexical Analysis Sol: Syntax analysis can be expanded but the
2
CFG describes the syntax becomes
cumbersome.
01. Ans: (a)
Sol: Comments are deleted during lexical 08. Ans: (b), (c) & (d)
analysis, by ignoring comments. Sol: The identifiers are entered into the symbol
table during lexical analysis phase.
02. Ans: (a)
Sol: The expansion of macro is done as the input,
09. Ans: (a) & (d)
tokens are generated during the lexical
analysis phase. Sol: As I/O to an external device is involved
most of the time is spent in lexical analysis
03. Ans: (a)
Sol: As soon as an identifier identifies as 10. Ans: 20
lexemes the scanner checks whether it is a
reserved word.
11. Ans: 7

04. Ans: (c)


12. Ans: (b)
Sol: Type checking is a semantic feature.
Sol: if, (, x , > =, y, ), {, x, =, x, +, y, ; , },
05. Ans: (d) else, {, x, =, x, –, y, ; , }, ; ,
Sol: A compiler that runs on one machine and
generates code for another machine is called 13. Ans: (a), (b) & (c)
cross compiler. Sol: All are tokens only.

06. Ans: (b)


Sol: The object code which is obtained from 14. Ans: (b)
Assembler is in Hexadecimal, which is not Sol: The specifications of lexical analysis we
executable, but it is relocated. write in lex language, when it run through
lex compiler it generates an output called
lex.yy.c.

India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
2 CSIT-Postal Coaching Solutions

15. Ans: (c) Chapter


Parsing Techniques
Sol: In $50000; $ is an illegal symbol identified 3
in lexical analysis phase
01. Ans: (b)
16. Ans: (c) Sol: As + is left associative the left most +
Sol: Syntax tree is input to semantic analyzer. should be reduced first
Character stream is input to lexical analyzer.
Intermediate representation is input to code 02. Ans: (d)
generation. Token stream is input to syntax Sol: S S
analyzer.
S S or S S

17. Ans: (a) & (b)


S S a S S
abc abc aa bbaac c caba c cbb
Sol:
3 3 1 5 2 2 2 2 a a S S
abc abc aa bbaac c ca bac cbb
3 3 1 5 2 2 5 2 S  S k1 SS k 2 SS k 3 ....SS k l
  k1 a k 2 a k 3 a

18. Ans: (b) So the sentence has an infinite number of


derivations.

03. Ans: (a)


Sol: The grammar which is both left and right
recursive is always ambiguous grammar.

04. Ans: (d)


Sol: S

a S b

b S a

a S b
b

Hence option (d) is correct.

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
3 Compiler Design

05. Ans: 2 12. Ans: 144


Sol: Sol: 3–2*4$2*3$2
E E
1*4$2*3$2
E + E E + E 1*16*9
16*9
id E + E E + E id
= 144
id id id id
13. Ans: (b)
06. Ans: (c) Sol: Rule ‘a’ evaluates to 4096
Sol: Rule ‘b’ evaluates to 65536
S S
Rule ‘c’ evaluates to 32
a S b S a S b S
14. Ans: (c)
 
b S a S Sol: A bottom up parsing technique builds the
a S b S
 derivation tree in bottom up and simulates a

  rightmost derivation in reverse
07. Ans: (d)
Sol: S Ad  Sad is indirect left recursion. 15. Ans: (a), (b) & (c)
Sol: Operator precedence parser is a shift reduce
08. Ans: (c) parser.
Sol: The production of the form A → A / is
left recursive and can be eliminated by 16. Ans: (c)
replacing with Sol: first(s) = first(A)  first(a)  first (Bb)
1
A → βA = {d}  {f, a} {e, b}={a,b,d,e,f}
1 1
A →  A /
17. Ans: (c)
09. Ans: (d) Sol: Follow(A) = first (C)
Sol: ↑ is least precedence and left associative = {f, } – {}  follow (S)
+ is higher precedence and right associative = {f}  {$}
= {f, $}
10. Ans: (a) & (c)
18. Ans: (c)
11. Ans: (b) & (d) Sol: first(A) = {a, c}, follow(A) = {b, c}
Sol: – > *, + = * first(A)  follow(A) = {c}

India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
4 CSIT-Postal Coaching Solutions

19. Ans: (d) 23. Ans: (a)


Sol: Follow(B) = First(C)First(x)Follow (D) Sol: First(A)= {*, +, id, }
= {y, m} {x}  Follow(A) First(B) Follow(A) = {d, $}
= {y, m, x}  {$}  {w, x}
= {w, x, y, m, $} 24. Ans: (a)
Sol: A left recursive grammar cannot be LL(1).

20. Ans: (a)


25. Ans: (c)
Sol: Follow(S) = {$}
Sol: The grammar is not LL(1), as on input
Consider S  [SX]
symbol a there is a choice.
Follow(S) = First (X)
The grammar is not LL(2), as input ab there
= {+,–, b}  {]}
is a choice.
= {+, – , b, ]} The grammar is LL(3) as on input abc there
Consider X  + SY is no choice.

Follow(S) = First (Y) 26. Ans: (c)


= {–}  Follow(X) Sol: To distinguish between
= {–}  {c, ]} S → if expr then stmt
= {–, c, ]} & S → if expr then stmt else stmt
Consider Y → – S X c We need a look ahead of 5 symbols.
Follow(S) = First(X)
= {+, –, b}  First(c) 27. Ans: (c)
= {+, –, b, c} Sol: * has a higher precedence than +.
 Follow(S) = {+, – , b, c, ], $} Consider

E
21. Ans: (c)
Sol: Follow(T) = {+, $} E + T
First(S) = {a, +, } T T* F
 Follow(T)  First (S) = {+}
F F id

22. Ans: (d) id id


Sol: Follow(A)=first(B)Follow(S)Follow(B)
28. Ans: (c)
={e}  {f}  {c, d}={c,d,e,$}.
Sol: M[B,y] contains both B→yA and B→ ε
Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
5 Compiler Design

29. Ans: (c) 37. Ans: (d)


Sol: A →  production is added in ‘A’ row and Sol: Lead(S) = {a}  {c}  Lead (B)  {d}
Follow(A) column. = { a,c,d,e}

30. Ans: (d) 38. Ans: (b)

Sol: S→aSbs and S→ both appear in ‘S’ row Sol: Trail(E) = {+}  Trail(T)
and ‘a’ column. = {+, *}  Trail(F)
= {+, *, ), id}
31. Ans: 0
Sol: The grammar is LL(1) Since the parse table 39. Ans: (b)
is free from multiple entries Sol: Lead (E) >+ and lead (E) contains {+, ↑, id}

32. Ans: (c) 40. Ans: (d)


Sol: Follow(S) = {$, a} Sol: Possible relations with ‘c’ are d>c and c >$
Follow(A) = {a} only.
S→ is entered into M[S, follow(S)]
= S→ 41. Ans: (b)

A→S is entered into M[S, follow(A)] Sol: The grammar E  E + E/a can have an
= A→S operator precedence parser but not an LR
parser.
33. Ans: (a) & (d)
Sol: An operator grammar is -free grammar and 42. Ans: (a)
no two non terminals are adjacent. Sol: The grammar
E → E + T | T, T → i
34. Ans: (c)
is left recursive. So it is not LL(1) but is
Sol: An operator grammar is ‘’ free grammar
LR(0). So (a) is true & (b) is false.
and no two non-terminals are adjacent.
The grammar
S → a | aA
35. Ans: (b)
Sol: The precedence relation between two A→b
adjacent terminals is =. has the LR(0) machine

36. Ans: (d) S → .a S → a.


a
Sol: As per normal HLL rules exponentiation is S → .aA S → a.A
right associative where as –, +, * are left A → .b
associative. Hence not LR(1) but is SLR(1).
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
6 CSIT-Postal Coaching Solutions

43. Ans: (d) 48. Ans: (b)


Sol: The grammar Sol: Every LL(1) is LR(1)
E → E +E | E  E | i
Can have a shift reduce parser if we use the 49. Ans: (a)
precedence and associativity of operations. Sol: The LR(0) machine for the grammar
The operator precedence technique works
with some ambiguous grammars. <life> → . <session> <session> <session>→ play. <session>
<session> → . play <session> <session> → .<session> <session>
<session> → . rest <session> → .play <session>
44. Ans: (d) <session> → .rest
Sol: The grammar
S → a | A, A → a <session> play <session> <session>
is neither LL(1) nor LR(0) & is ambiguous. play
<life> → <session> <session> <life> → <session> <session>.
No ambiguous grammar can be LL or LR. <session> → . play <session>
<session> → . rest

45. Ans: (a), (b) & (c) rest


rest rest
Sol: No ambiguous grammar can be LR(1). <session>
<session> → rest.
46. Ans: (c) <life> → <session> <session>.

Sol: The grammar


S → Aa | Bb
50. Ans: (b)
A→
Sol: The LR(0) machine
B →  is LL(1) but not LR(0)
E → FR
The LR(0) machine has a conflict.
R → E/
S → .Aa A a F → id R
S → A.a S → Aa. E → FR.
S → .Bb E → F.R
B b E → .FR F R → .*E
A→. S → B.b S → Bb. F → .id R→. 
B→.  R → .
A → .
conflict id
B → . F
*
The grammar is F →id. R → *.E
S → a | ab E → .FR E
id R → *E.
Is LR(2) & not LR(1). F → .id

47. Ans: (a), (b) & (c) 51. Ans: (b)


Sol: Every LR(0) grammar is SLR(1)
Sol:
Every SLR(1) grammar is LALR(1) S1→.S
Every LALR(1) grammar is LR(1) S→.SB
The grammar S → a is both LL(1) & LR(0) S→.A
trivially. A→.a

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
7 Compiler Design

52. Ans: 7 56. Ans: (d)


Sol: (2) Sol: The grammar is ambiguous.
(1)
S1.S A A
S
(3) (6)
1
S →.S A A + A Or A + A
S.AA SA.A SAA.
A.aA A A.aA a
(4) A+A i i A+A
A.b A.b
b
(5)
a
(4) (7) i i i i
Aa.A A There are two derivation trees for the
b (5) AaA.
A.aA a sentence i + i + i. As the grammar is
Ab. (4)
A.b
b ambiguous it cannot be LL or LR. So, (a),
(5)
(b), (c), are ruled out. The answer is (d).

53. Ans: 6 57. Ans: 2


Sol: Sol: The LR(0) items of the grammar is
I0
S1 → . S d A → d.I
1
S →.S a S→a.Bb S → . AaAb B → d.
S→.aBb B→.BeS S → . BbBa
S→.d B→.S A→.d
B→.f B → .d
S→.aBb Reduce – Reduce conflict.
S→.d
54. Ans: 2 58. Ans: (a)
Sol: Sol: S1 → .S, $
S → . aAd, $ b S → a.Ad, $
S → .bBd, $ S → a.Be, $
E → T. A → .c, d
E1 → . E T S–R S → .aBe, $
T → T.* B → .c, e
E→.E+T conflict S → .bAe,
E→.T F
c Ⓧ
T→.T*F b
T → .F A → c., d
F → . id S → b.Bd, $ B → c., e
1 S → b.Ae,$
E E → E. + E→E+.T B → .c, d A → c., e Ⓨ
E→E.+T c
T→.T*F A → .c, e B → c., d
T→.F
F→.id T E→E+T. S–R Consider the partial LR(1) machine shown
T→T.*F
conflict
above. The states Ⓧ & Ⓨ have a common
core. However if we merge the states to
55. Ans: (b) obtain the LALR(1) machine we will end up
Sol: An input ‘a’ the set has with conflicts. So the grammar is LR(1) but
A→Ba.c, B→a. C→. not LALR(1).

India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
8 CSIT-Postal Coaching Solutions

59. Ans: (a) 62. Ans: (c)


Sol: S → .Aa, $ Sol: S→.A,$ S→. A, $
S → . bAc, $ b S → b.Ac, $
S → .Bc, $ S → b.Ba, $ A→. AB, $/ Follow (A)  A→. AB, $/b
S → .bBa, $ A → .d, c
A → .d, a B → .d. a A→. , $/ Follow (A) A→., $/b
B → .d, c d Ⓨ
d A → d., c 63. Ans: (d)

B → d., a
A → d., a
Sol:
B → d., c

Consider the partial LR(1) machine above. S


S1  S, $
S1  .S, $
S  S. a, $
The states Ⓧ&Ⓨ have a common core but S .aS, $
S .Sa, $ 3-Reduce-Conflict S-R Conflict
a
S→.a, $ S  a.S, $
different look ahead sets. If we merge S S  a.S., $
S  a., $ S  S. a, $
Ⓧ&Ⓨ So obtain the LALR(1) a conflict S→.a, s, S→Sa.$, S→.a,$
No. of conflicts=2
arise.

60. Ans: (b) 64. Ans: (c)


Sol: LR(1) items of the grammar is Sol:
S1  .S. $
① ②
S . L=R, $
A1  .A, $ A  a. A,$/b ③ S . R, $
A  .aA, $/b a A  .aA, $/b A A  aA. $/b L→. *R,=/ $
A  .Ab, $/b A  .Ab, $/b A  A.d, $/b L→.id, = /$
b
A  .d, $/b A  .d, $/b R→.L, $

A  Ab., $/b
Item 3 has Shift-Reduce conflict. 65. Ans: (b)

61. Ans:(d) Sol:


Sol: S1 →. S S1 → S. S S→
S
I0 I1 I4 S→. S→ S. SS.+
SS+ S+ S→ SS.*
S  . S, $ b S  b. Ac, $ d S  bd . a, $
S  .Aa, $ S  b. da, $
S→. S→ S. S→
A  d ., c
S  .bAc, $ A  . d, c a SS* S* S.S+
S  .dc, $ I5 S→. a S→. SS+ S→ S.S*
S  .bda, $ I2
c S→bda.,$ S→.SS* S→.SS+
A  .d, a d S  d. c, $ S→.a S→.SS*
Ad.,a I3
S→.a
S  dc., $

As there is no conflict the grammar is in


LALR(1).

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
9 Compiler Design

The given grammar is LR(0) as there are no Chapter


Syntax Directed Translation Schema
conflicts. Every LR(0) grammar is SLR(1), 4
LALR(1) and LR(1). Given grammar is left
recursive and it is not LL(1). 01. Ans: (c)
Sol: SDT is part of Semantic Analysis
66. Ans: (d)
Sol: The grammar is LL(1) 02. Ans: (a) & (b)

S1  .S Sol: The attribute ‘val’ is synthesized and the


S  .(S) SDT is S-attributed and every ‘S’-attributed
S .
is L-attributed definition
Every LL(1) is LR (1)
03. Ans: (a) & (c)
67. Ans: (b)
Sol: P → YQ{Q.q = g(P.p,Y.y)}
Q is taking values from parents and Left
68. Ans: (b)
siblings. → L-attributed
Sol: SLR(1) & LALR(1) have the same number
Since Left siblings are involved not
of states. LR(1) may have more.
S-attributed.
69. Ans: 10
attribute SDT
Sol: The number of states in both SLR(1) and
LALR(1) are same.
attribute SDT
70. Ans: (c)
Sol: YACC uses LALR(1) parse table as it uses
less number of states requires less space and
takes less time for the construction of parse
tree. 04. Ans: (c)
Sol: The SDD is used to convert the given binary
number to decimal number and the answer is
5.625

India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
10 CSIT-Postal Coaching Solutions

05. Ans: (c) 08. Ans: (c)


Sol: For input: a + b – c Sol: (A (AB))

G Neg(AND(A, OR(NOT(A),B)))
E = – + abc
F Neg(AND(A, OR(NOT(A),B)))

E = + ab – T=c  F AND(A, OR(NOT(A),B))


1

c
( F ) AND(A, OR(NOT(A),B))
E=a + T=b

A=  F OR(NOT(A),B)
T=a b
F

a ( F ) OR(NOT(A),B)

06. Ans: (c) A=  F=


F B
Sol: A B
S

09. Ans: (c)


S S c Sol: The rightmost derivation is
b E → E +E → E + E + E
S S c →E+E+E+E
→E+E+E+E+E
a b
a+b+c+d+e
Bottom up traversal of the parse tree results
the output: 10. 10. Ans: (c)
Sol: The leftmost derivation for aaaa is S
4 4
S → aS
07. Ans: (b) a S
→ aaS
Sol: counts the pairs of matching parenthesis. 3 3
→ aaaS
a S
→ aaaa 2 2
The dependency graph a S
1
11. Ans: (a) a

Sol: The rightmost derivation is


S → aB → aa BB →aa Bb → aa bb

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
11 Compiler Design

12. Ans: (c) 16. Ans: (a)


Sol: S → aA {print 1} S Sol: According to the action of shift reduce
S → a {print 2} a a b parser, the parse tree constructed is
a A
A → Sb {print 3} a s b 231 E
Input: aab S b a A

S E print (↑)
a ↑ E

13. Ans: (b)


Sol: c print (c)
S E * E print (*)

Print 1 a print(a) b print (b)


X Y c

 The Depth First Traversal of the above parse


Print 4
Y b Print tree is a b * c ↑
L 3S

c Print 5

The depth first traversal of a parse tree


generates an output 5, 3, 4, 1.

14. Ans: (a) & (c)


Sol: A A

A + A (1) A + A (1)

A + A (1) a (2) a (2) A + A (1)

a a (2) a (2) a (2)


(2)

15. Ans: (b)


Sol: As the grammar is ambiguous & we do not
specify the precedence of operators either
postfix form may result depending on the
parser implementation.
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
12 CSIT-Postal Coaching Solutions

Chapter 07. Ans: (a)


Intermediate Code Generation
5 Sol: 1. (+, b, c)
2. (NEG, (1))
01. Ans: (c) 3. (*, a, (2))
Sol: The purpose of using intermediate codes in
08. Ans: 3
compilers is to reuse machine independent
Sol: Rewriting the given assignments
code for other compilers.
x1 = u1 – t1; → needs two new variables
y2 = x1  v1; → needs three new variables
02. Ans: (a), (b) & (c)
x3 = y2 + w1; → needs four new variables
Sol: The final result is the machine language
y4 = t2 – z1; → needs five new variables
code. The others are all standard
y5 = y2 + w1 + y4; → needs 3 new variables
intermediate forms.
atmost

03. Ans: (a), (b) & (c) 09. Ans: (b)


Sol: TAC is a statement that contains atmost Sol: All assignments in SSA are to variables with
three memory references. distinct names
p3 = a – b
04. Ans: (a), (b) & (c) q4 = P3 * c
Sol: TAC can be implemented as a record p4 = u * v
structure with fields for operator and q5 = P4 + q4
arguments as Quadruples, triples and
10. Ans: (d)
indirect triples.
Sol: Peephole optimization expression is the final
code.
05. Ans: (b)
Sol: The Quadruples is record structure with four 11. Ans: (d)
fields. Sol: DAG for the expression a*b*b is
1. (*, b, c, T1) *
2. (+, a, T1, T2)
3. (–, T2, d, T3) *
a b
06. Ans: (c)
Sol: (1) (and, b, c, T1) 12. Ans: (b)
(2) (or, a, T1, T2, c, T3) Sol: DAG is constructed based on precedence
(3) (or, T2, c, T3) and associativity of operators and option (b)
is the correct representation.

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages
13 Compiler Design

13. Ans: 4 Chapter


Code optimization
Sol:
+ a + e 6

c d 01. Ans: (a)

Number of nodes = 4 Sol: It is called reduction in strength


example: replace * by +
14. Ans: (b)
Sol: d n2
+ e5 02. Ans: (c)
n3
n1 e3 + Sol: It is classical example of reduction in
e – e6
e4 a e7 strength
e1 e2 + n4
n6 d
+ e8 03. Ans: (c)
e9
a e10 b Nodes = 8 Sol: Machine dependent optimization based on
c
n7 Edges = 10
n8 the machine properties and machine
a=b+c
c=a+d dependent optimization is one of it.
d=b+c
e=d–b 04. Ans: (a) & (b)
a=e+d
Sol: Copy propagation generally creates dead
Number of nodes = 8
Number of edges = 10 code that can then be eliminated.
Eliminating dead code improves efficiency
15. Ans: (a)
of the program by avoiding the execution of
Sol: In C the storage for array is row major order.
Between X[l] [32] [8] & X [l+1] [32] [8] unnecessary statements at run time. If one
there must be 328 integer of type int i.e variable is assigned to another, replace uses
3284 = 1024 bytes. So in X[i] [j] [k] for a of the assigned variable with the copied
variation of index i by 1, 1024 bytes must be variable.
skipped. So the answer must be (a)

16. Ans: (b) 05. Ans: (c)


Sol: (1) (+, c, d)
Sol: A fragment of code that resides in the loop
(2) ( –, b, (1))
and computes the same value at each
(3) (*, e, f)
(4) (+, (2), (3)) iteration is called loop-invariant code.
(5) (=, a, (4))
India’s Best Online Coaching Platform for GATE, ESE, PSUs, SSC‐JE, SSC, Banks, Groups & PSC Exams
Enjoy a smooth online learning experience in various languages at your convenience
14 CSIT-Postal Coaching Solutions

06. Ans: (a) 09. Ans: (b)


Sol: Eliminating dead code improves efficiency Sol: b + c is not common sub expression as the
of the program by avoiding the execution of value of b changed between 1st and 3rd
statements.
unnecessary statements at run time

10. Ans: (b)


07. Ans: (c)
Sol: It has many advantages like optimization
Sol: Before compilation a = b + 2*2.5 after
and Program analysis is more accurate on
compilation a = b + 5
intermediate code than on machine code.
08. Ans: (b)
11. Ans: (d)
Sol: Control flow graph of the above code is
Sol: x = 4  5  x = 20 is called constant
Start folding.

12. Ans: (d)


S
1 Sol: Two for loops can be optimized here as
code contains loop-invariant computation.
S2 4*j can be evaluated once so there is scope
of common sub expression elimination in
S3–S9 this code.
The operator * can be replaced by + so there
is scope of strength reduction in this code.
S 10, 11
No dead code in this program segment.

end

Regular Live Doubt clearing Sessions | Free Online Test Series | ASK an expert
Affordable Fee | Available 1M |3M |6M |12M |18M and 24 Months Subscription Packages

You might also like