Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Evaluate the postfix expression: 5 9 + 4 * 2 +
- A. 59
- B. 57
- C. -58
- D. 58
Correct answer: D. 58
Scan left to right with a stack: push operands, and on an operator pop b then a and push a op b, preserving operand order (important for - and /). Result 58.
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
- A function makes two recursive calls on an array of size n, each on a half of size n/2, and does O(n) extra work to combine the results…
- A singly linked list has nodes at positions 0..5 holding 74 -> 10 -> 74 -> 58 -> 91 -> 24, but the last node's next pointer points back to…
- Selection sort (ascending, swap the minimum of the unsorted suffix into place each pass, skipping the swap if it is already in place) is…
- How many adjacent swaps does bubble sort (ascending) make on [97, 9, 32, 5, 21, 45, 53, 34]?
- Standard top-down merge sort is run on [3, 48, 14, 99, 61, 71, 8, 15]. How many element comparisons happen during all the merge steps…
- Quicksort with Lomuto partitioning (last element as pivot) sorts [84, 38, 96, 7, 19, 64, 7, 94]. How many swaps happen in total, across…