Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Evaluate the postfix expression: 4 3 5 + * 3 -
- A. 35
- B. 27
- C. 29
- D. 44
Correct answer: C. 29
Scan left to right with a stack: on an operator pop b then a and push a op b (note the order for −). Result 29.
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
- How many swaps does bubble sort (adjacent swaps, ascending) make on [33, 25, 8, 52, 16, 15, 22, 24, 10]?
- A sorted array holds the 39 values 2, 5, 8, … (step 3). Binary search with mid = ⌊(lo+hi)/2⌋ and 0-based indices looks for 50. How many…
- Keys 81, 58, 72, 25, 31 are inserted into a hash table of size 10 with h(k) = k mod 10 and linear probing. At which index is 58 stored?
- A circular queue is implemented in an array of size 7 with front = 4 and rear = 5 (rear indexes the last stored element, the queue is…
- Two sorted lists [6, 16, 24, 29] and [20, 22, 25, 35] are merged using the standard merge step. How many element comparisons are made?
- How many swaps does bubble sort (adjacent swaps, ascending) make on [10, 24, 35, 46, 54, 16, 12, 2, 43]?