Practice mode Data Structures

What is the postfix form of A ^ B ^ C, where ^ is exponentiation and is right-associative?

Correct answer B. A B C ^ ^

Explanation

Exponentiation groups from the right, so A ^ B ^ C means A ^ (B ^ C). B ^ C becomes B C ^, and raising A to that result gives A B C ^ ^. The tempting A B ^ C ^ corresponds to (A ^ B) ^ C, which is a different value. In the shunting-yard algorithm, an incoming ^ does not pop another ^ from the stack for this reason.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.