Data Structures & AlgorithmsModerateTCS Digital · Infosys SP
What is the minimum number of stacks needed to evaluate a fully parenthesised infix expression directly (without converting it first), using Dijkstra's two-stack algorithm?
- A. 3
- B. 0
- C. 2 (one for operands, one for operators)
- D. 1
Correct answer: C. 2 (one for operands, one for operators)
The two-stack algorithm pushes operands and operators onto separate stacks and applies an operator to the top two operands on each ')'. Postfix evaluation alone needs just one operand stack.
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
- Merge sort and quick sort are compared. Which statement is correct?
- Bars of width 1 have heights [7, 3, 3, 6, 1, 3, 7, 1, 1]. How many units of rain water are trapped between them (two-pointer method with…
- Bubble sort (ascending; each pass compares adjacent pairs left to right and swaps if out of order) is applied to [49, 52, 21, 37, 35, 19…
- 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 = "aaaaabaaa" z…
- 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[0][1] = 5…
- An array of size 9 holds the numbers 1..9, except that one number is missing and one number appears twice: [6, 5, 1, 3, 4, 7, 2, 8, 2]…