Data Structures & AlgorithmsHardIBM · Deloitte pattern
What is the postfix (Reverse Polish) form of the infix expression "i *(f + c)- a / h", built with the standard stack-based conversion (^ right-associative, others left-associative)?
- A. i f c + * a h / -
- B. i f c + * a - h /
- C. - / h a * + c f i
- D. i f c a h / - + *
Correct answer: A. i f c + * a h / -
Using a stack to hold pending operators and popping higher-or-equal precedence operators before pushing a new one (left-associative) gives "i f c + * a h / -". Treating all operators as equal precedence instead would wrongly give "i f c + * a - h /".
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
- Array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is left-rotated by d = 1 positions using the reversal algorithm (reverse first d, reverse rest…
- A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(7)?
- Kadane's algorithm runs on the array [-4, 3, 9, 3, 3, -6, 7, 4, 6] to find the maximum sum of a contiguous subarray. What sum does it…
- Binary search for first/last occurrence runs on the sorted array [2, 5, 6, 16, 19, 19, 20, 21] for target 19. What (first index, last…
- Array [1, 2, 3, 4, 5, 6, 7, 8, 9] is left-rotated by d = 3 positions using the reversal algorithm (reverse first d, reverse rest, reverse…
- Two sorted linked lists [8 → 33 → 35 → 40] and [2 → 13 → 16] are merged with the standard O(n+m) two-pointer merge (always take the…