Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Theory questions 1. Using a stack, and the algorithm discussed in the videos, ma

ID: 3640772 • Letter: T

Question

Theory questions
1. Using a stack, and the algorithm discussed in the videos, manually trans-
form the following expressions from inx to postx notation
(a) A + B - C
(b) A + B * C * D
(c) C - A * (F - D) * (F + C)
(d) (A - B * (B + (C + E) * B) * F
2. Using a stack, and the algorithm discussed in the videos, manually show
the steps to evaluate the expressions from a) b) c) and d) when
A = 1 B = 2 C = 3 D = 4 E = 5 F = 3
3. Given that Q is a FIFO structure, what would be the contents of Q after
the following pseudocode is executed? The data are
7; 23; 8; 0; 34; 5; 11; 67; 0; 5; 0; 44; 99
Q = createQueue
loop (not end of file)
read number
if (number not 0)
enqueue (number)
end if
end loop
loop(1:4)
dequeue()
end loop

Explanation / Answer

1. a) A+B-C Input Stack Output A $ A + $+ A B $+ AB - $- AB+ C $- AB+C $ AB+C- Output: AB+C- b) A+B*C*D Input Stack Output A $ A + $+ A B $+ AB * $+* AB C $+* ABC * $+* ABC* D $+* ABC*D $ ABC*D*+ Output: ABC*D*+ c) C - A * (F - D) * (F + C) Input Stack Output C $ C - $- C A $- CA * $-* CA ( $-*( CA F $-*( CAF - $-*(- CAF D $-*(- CAFD ) $-* CAFD- * $-* CAFD-* ( $-*( CAFD-* F $-*( CAFD-*F + $-*(+ CAFD-*F C $-*(+ CAFD-*FC ) $-* CAFD-*FC+ $ CAFD-*FC+*- Output: CAFD-*FC+*- d) (A - B * (B + (C + E) * B) * F) Input Stack Output ( $( A $( A - $(- A B $(- AB * $(-* AB ( $(-*( AB B $(-*( ABB + $(-*(+ ABB ( $(-*(+( ABB C $(-*(+( ABBC + $(-*(+(+ ABBC E $(-*(+(+ ABBCE ) $(-*(+ ABBCE+ * $(-*(+* ABBCE+ B $(-*(+* ABBCE+B ) $(-* ABBCE+B*+ * $(-* ABBCE+B*+* F $(-* ABBCE+B*+*F ) $ ABBCE+B*+*F*- Output: ABBCE+B*+*F*- 2. a) 12+3- Input Stack 1 $1 2 $12 + $3 3 $33 - $0 Output: 0 b) 123*4*+ Input Stack 1 $1 2 $12 3 $123 * $16 4 $164 * $1(24) + $(25) Output: 25 c) 3134-*33+*- Input Stack 3 $3 1 $31 3 $313 4 $3134 - $31(-1) * $3(-1) 3 $3(-1)3 3 $3(-1)33 + $3(-1)6 * $3(-6) - $9 Output: 9 d) 12235+2*+*3*- Input Stack 1 $1 2 $12 2 $122 3 $1223 5 $12235 + $1228 2 $12282 * $122(16) + $12(18) * $1(36) 3 $1(36)3 * $1(108) - $(-107) Output: -107 3. After the pseudo code is executed, the output will be: 5;11;67;5;44;99