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 ?
- A.
6 and 6
- B.
6 and 7
- C.
7 and 7
- D.
7 and 6
Attempted by 80 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.