1.What data structure is used when
converting an infix notation to prefix notation?
a) Stack
b) Queue
c) B-Trees
d) Linked-list
a) Stack
b) Queue
c) B-Trees
d) Linked-list
Answer: a
Explanation: First you reverse the given equation and carry out the algorithm of infix to postfix expression. Here, the data structure used is stacks.
Explanation: First you reverse the given equation and carry out the algorithm of infix to postfix expression. Here, the data structure used is stacks.
2. What would be the Prefix notation
for the given equation?
A+(B*C)
a)+A*CB
b)*B+AC
c)+A*BC
d) *A+CB
b)*B+AC
c)+A*BC
d) *A+CB
Answer: c
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the bracket evaluates to CB* and outside the bracket evaluates to A+ therefore getting CB*A+. Reversing this and we get +A*BC.
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the bracket evaluates to CB* and outside the bracket evaluates to A+ therefore getting CB*A+. Reversing this and we get +A*BC.
3.What would be the
Prefix notation for the given equation?
(A*B)+(C*D)
a)+*AB*CD
b)*+AB*CD
c)**AB+CD
d) +*BA*CD
b)*+AB*CD
c)**AB+CD
d) +*BA*CD
Answer: a
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the brackets evaluate to DC* and BA* respectively giving us DC*BA*+ in the end. Reversing this we get the +*AB*CD.
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-postfix algorithm. The equation inside the brackets evaluate to DC* and BA* respectively giving us DC*BA*+ in the end. Reversing this we get the +*AB*CD.
4. What would be the
Prefix notation for the given equation?
A+B*C^D
a)+A*B^CD
b)+A^B*CD
c)*A+B^CD
d) ^A*B+CD
b)+A^B*CD
c)*A+B^CD
d) ^A*B+CD
Answer:a
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*^. Operators are pushed into the stack and popped if its preference is greater than the one which is getting pushed. In the end all operators are popped. The equation evaluates to DC^B*A+. Reversing this we get our following answer.
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*^. Operators are pushed into the stack and popped if its preference is greater than the one which is getting pushed. In the end all operators are popped. The equation evaluates to DC^B*A+. Reversing this we get our following answer.
5.
Out of the following operators (^, *, +, &, $), the one having highest
priority is _________
a)+
b)$
c)^
d) &
a)+
b)$
c)^
d) &
Answer:c
Explanation: According to the algorithm (infix-prefix), it follows that the exponentiation will have the highest priority.
Explanation: According to the algorithm (infix-prefix), it follows that the exponentiation will have the highest priority.
6. Out of the following operators (|,
*, +, &, $), the one having lowest priority is ________
a) +
b) $
c) |
d) &
a) +
b) $
c) |
d) &
Answer: c
Explanation: According to the algorithm (infix-prefix), it follows that the logical OR will have the lowest priority.
Explanation: According to the algorithm (infix-prefix), it follows that the logical OR will have the lowest priority.
7. What would be the
Prefix notation for the given equation?
A^B^C^D
a)^^^ABCD
b)^A^B^CD
c)ABCD^^^
d) AB^C^D
b)^A^B^CD
c)ABCD^^^
d) AB^C^D
Answer: a
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. Here we have to remember that the exponentiation has order of associativity from right to left. Therefore the stack goes on pushing ^. Therefore resulting in ^^^ABCD
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. Here we have to remember that the exponentiation has order of associativity from right to left. Therefore the stack goes on pushing ^. Therefore resulting in ^^^ABCD
8. What would be the
Prefix notation for the given equation?
a+b-c/d&e|f
a)|&-+ab/cdef
b)&|-+ab/cdef
c)|&-ab+/cdef
d) |&-+/abcdef
b)&|-+ab/cdef
c)|&-ab+/cdef
d) |&-+/abcdef
Answer:a
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows |&+*/.
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows |&+*/.
.
9. What would be the
Prefix notation for the given equation?
(a+(b/c)*(d^e)-f)
a)-+a*/^bcdef
b)-+a*/bc^def
c)-+a*b/c^def
d) -a+*/bc^def
b)-+a*/bc^def
c)-+a*b/c^def
d) -a+*/bc^def
Answer: b
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*/^. Brackets have the highest priority. The equations inside the brackets are solved first.
Explanation: Reverse the equation or scan the equation from right to left. Apply the infix-prefix algorithm. The preference order in ascending order are as follows +*/^. Brackets have the highest priority. The equations inside the brackets are solved first.
10. What would be the
Prefix notation and Postfix notation for the given equation?
A+B+C
a) ++ABC
and AB+C+
b) AB+C+ and ++ABC
c) ABC++ and AB+C+
d) ABC+ and ABC+
b) AB+C+ and ++ABC
c) ABC++ and AB+C+
d) ABC+ and ABC+
Answer: a
Explanation: For prefix notation there is a need of reversing the giving equation and solving it as a normal infix-postfix question. We see that it doesn’t result as same as normal infix-postfix conversion.
Explanation: For prefix notation there is a need of reversing the giving equation and solving it as a normal infix-postfix question. We see that it doesn’t result as same as normal infix-postfix conversion.
No comments:
Post a Comment