Consider the following pseudo-code. ๐ฟ1: ๐ก1 = โ1 ๐ฟ2: ๐ก2 = 0 ๐ฟ3: ๐ก3 = 0โฆ
2024
Consider the following pseudo-code.
ย ย ย ย ๐ฟ1: ๐ก1 = โ1
ย ย ย ย ๐ฟ2: ๐ก2 = 0
ย ย ย ย ๐ฟ3: ๐ก3 = 0
ย ย ย ย ๐ฟ4: ๐ก4 = 4 โ ๐ก3
ย ย ย ย ๐ฟ5: ๐ก5 = 4 โ ๐ก2
ย ย ย ย ๐ฟ6: ๐ก6 = ๐ก5 โ ๐
ย ย ย ย ๐ฟ7: ๐ก7 = ๐ก4 + ๐ก6
ย ย ย ย ๐ฟ8: ๐ก8 = ๐[๐ก7]
ย ย ย ย ๐ฟ9: if ๐ก8 <= ๐๐๐ฅ goto ๐ฟ11
ย ย ย ย ๐ฟ10: ๐ก1 = ๐ก8
ย ย ย ย ๐ฟ11: ๐ก3 = ๐ก3 + 1
ย ย ย ย ๐ฟ12: if ๐ก3 < ๐ goto ๐ฟ4
ย ย ย ย ๐ฟ13: ๐ก2 = ๐ก2 + 1
ย ย ย ย ๐ฟ14: if ๐ก2 < ๐ goto ๐ฟ3
ย ย ย ย ๐ฟ15: ๐๐๐ฅ = ๐ก1
Which one of the following options CORRECTLY specifies the number of basic
blocks and the number of instructions in the largest basic block, respectively ?
Answer: D. 7 and 6 โ tep 1: Identify leadersRules for leaders (start of basic blocks): First instruction is a leader โ L1 Targets of jumps are leaders โ L3, L4, L11, L15โฆ
- A.
6 and 6
- B.
6 and 7
- C.
7 and 7
- D.
7 and 6
Attempted by 119 students.
Show answer & explanation
Correct answer: D
tep 1: Identify leaders
Rules for leaders (start of basic blocks):
First instruction is a leader โ L1
Targets of jumps are leaders โ L3, L4, L11, L15
Instruction following a conditional or unconditional jump is a leader โ L10, L13
Leaders: L1, L3, L4, L10, L11, L13, L15
So, 7 basic blocks (one per leader).
Step 2: Form basic blocks
BB1: L1, L2 โ straight-line until L3 (next leader)
BB2: L3 โ only L3
BB3: L4, L5, L6, L7, L8, L9 โ ends with conditional jump
BB4: L10 โ single instruction after jump
BB5: L11, L12 โ loop back to L4
BB6: L13, L14 โ loop back to L3
BB7: L15 โ final instruction
Step 3: Count instructions in each BB
BB | Instructions |
|---|---|
BB1 | 2 (L1-L2) |
BB2 | 1 (L3) |
BB3 | 6 (L4-L9) |
BB4 | 1 (L10) |
BB5 | 2 (L11-L12) |
BB6 | 2 (L13-L14) |
BB7 | 1 (L15) |
Largest BB = 7? Actually check: BB3 has 6 instructions (L4-L9), which is largest.
So largest BB = 6 instructions
Number of BB = 7
Step 4: Correct Answer
Numberย ofย BBย =ย 7,ย Largestย BBย =ย 6ย instructions\text{Number of BB = 7, Largest BB = 6 instructions}Numberย ofย BBย =ย 7,ย Largestย BBย =ย 6ย instructions
Answer: D โ 7 and 6
A video solution is available for this question โ log in and enroll to watch it.