Data Structures & AlgorithmsHardTCS NQT · Infosys pattern
What is the postfix (Reverse Polish) form of the infix expression "j + e * f -(b + a)", built with the standard stack-based conversion (^ right-associative, others left-associative)?
- A. - + a b + * f e j
- B. j e + f * b a + -
- C. j e f * + b a + -
- D. j e f b a + - * +
Correct answer: C. j e f * + b a + -
Using a stack to hold pending operators and popping higher-or-equal precedence operators before pushing a new one (left-associative) gives "j e f * + b a + -". Treating all operators as equal precedence instead would wrongly give "j e + f * b a + -".
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
- What is the sum of the minimum element over every contiguous subarray of [8, 1, 5, 4, 4, 2]?
- Binary search for first/last occurrence runs on the sorted array [5, 6, 7, 7, 15, 18, 19, 20] for target 7. What (first index, last index)…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- A singly linked list holds 36 -> 38 -> 51 -> 57 -> 28 -> None (in that order, 5 nodes). Using the standard two-pointer technique (advance…
- Evaluate the postfix expression: 4 3 7 + 1 -
- A circular queue is implemented in an array of size 9 with front = 1 and rear = 8 (rear indexes the last stored element, the queue is…