Data Structures & AlgorithmsHardGATE CS · ICPC regional
Convert the infix expression a+b*(c-d)/e to postfix with the shunting-yard algorithm (operators '+', '-', '*', '/' with '*' and '/' binding tighter, left-associative). What is the postfix string?
- A. abcd-*e/+
- B. acbd-*e/+
- C. abdc-*e/+
- D. bacd-*e/+
Correct answer: A. abcd-*e/+
Operands go straight to the output; operators wait on the stack and are popped while the top has priority at least as high. The closing bracket pops the subtraction first.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A 3-litre jug and a 5-litre jug start empty and you can fill either, empty either, or pour one into the other until one is full or empty…
- Reverse the sublist between positions 3 and 6 (1-based, inclusive) of the list 1, 2, 3, 4, 5, 6, 7, 8. What value is at position 4 of the…
- Rotate the list 1, 2, 3, 4, 5, 6, 7 to the right by 10 positions (each rotation moves the last node to the front). What value is at the…
- Stable partition of the list [1, 4, 3, 2, 5, 2] around x = 4 puts every node with value < 4 first, then every node with value >= 4…
- Asteroids move in a row; positive values move right and negative values move left, and when two meet the one with the smaller absolute…
- Daily temperatures are 73, 74, 75, 71, 69, 72, 76, 73. For each day, the wait is the number of days until a warmer day (0 if none). What…