Data Structures & AlgorithmsHardWipro · Accenture pattern
^ is exponentiation (highest precedence, right-associative). What is the postfix form of A + B * C ^ D ^ E − F?
- A. A B C D ^ E ^ * + F −
- B. A B C D E ^ ^ * + F −
- C. A B C D E ^ ^ * F − +
- D. A B C * D ^ E ^ + F −
Correct answer: B. A B C D E ^ ^ * + F −
C ^ D ^ E = C ^ (D ^ E) → C D E ^ ^; times B → B C D E ^ ^ *; then A + that, and − F last because + and − are left-associative. Treating ^ as left-associative gives C D ^ E ^.
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
- What is the value of the postfix expression 2 3 2 ^ ^ (^ means power)?
- What is the minimum stack size needed to evaluate the postfix expression a b c d + e f − / + ?
- A queue is built from two stacks: enqueue pushes onto stack IN; dequeue pops from stack OUT, first moving everything from IN to OUT only…
- An array has only 0s, 1s and 2s. The Dutch National Flag algorithm sorts it in one pass. What are its time and extra space?
- n integers, each in the range 0 to n² − 1, must be sorted. Which approach sorts them in O(n) time?
- How many comparisons does top-down merge sort (split in halves, stop comparing when one side runs out) make on [5, 1, 7, 3, 20, 15, 30, 25]?