Data Structures & AlgorithmsHardGATE CS · Product placement
Evaluate the postfix expression 3 5 4 6 1 ÷ − + + (all divisions are exact). What is its value, and what is the maximum number of operands on the stack at any moment?
- A. 5; 5
- B. 6; 5
- C. 5; 4
- D. 6; 6
Correct answer: B. 6; 5
On each operator pop b (top) then a, and push a op b — the first popped value is the RIGHT operand. Tracing gives 6, with the stack peaking at 5 values. Swapping the operand order gives 5.
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
- Count palindromic substrings by expanding around all 2n − 1 centres, and also count DISTINCT palindromic substrings. What is printed?…
- Top-down merge sort (split at mid = n // 2, recurse, then merge, stopping comparisons when one side runs out) sorts [33, 53, 13, 42, 11…
- Assertion (A): Removing duplicates from a sorted array can be done in place in O(n) time with two pointers. Reason (R): In a sorted array…
- Assertion (A): Quick sort with the last element as pivot takes Θ(n²) time on an array that is already sorted. Reason (R): On sorted input…
- A Python 2-D list is created two ways and one cell is set. What is printed? python a = [[0] 3] 3 b = [[0] 3 for in range(3)] a[2][2] = 5…
- Rearrange a linked list so that nodes at odd POSITIONS (1st, 3rd, …) come first, followed by the even-position nodes, keeping relative…