Data Structures & AlgorithmsHardGATE CS · DSA
Evaluate the postfix expression 1 9 9 ÷ 4 − 7 + − (all divisions are exact). What is its value, and what is the maximum number of operands on the stack at any moment?
- A. -3; 3
- B. -3; 4
- C. 9; 3
- D. 9; 2
Correct answer: A. -3; 3
On each operator pop b (top) then a, and push a op b — the first popped value is the RIGHT operand. Tracing gives -3, with the stack peaking at 3 values. Swapping the operand order gives 9.
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
- Floyd's cycle detection on a list whose last node links back into the list. What does this print (meeting value, cycle-start value, cycle…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "abaabaaba" z…
- Kadane's algorithm is applied to an array whose elements are ALL negative, using the version cur = max(x, cur + x), best = max(best, cur)…
- Remove the n-th node from the END of a linked list in one pass, using a dummy node and a gap of n between two pointers. What is printed?…
- Z-array: z[i] is the length of the longest common prefix of s and s[i:], with z[0] defined as 0. What is printed? python s = "bbaaaabab" z…
- Asteroids move along a line: positive values move right, negative move left; on collision the smaller (by absolute value) explodes, equal…