Multiple choice

Identify the correct sequence for stack, if the input sequence is 1, 2, 3, 4 and 5.

  1. 4, 3, 5, 1 and 2

  2. 4, 3, 5, 2 and 1

  3. 5, 4, 1, 2 and 3

  4. 5, 4, 3, 1 and 2

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In stack, the element is inserted in last which should be taken out first. For example, for sequence 4, 3, 5, 2 and 1, first insert 1, 2, 3, 4 then take out 4 and 3; here stack content is 2 and 1, again insert 5 and take out 5, 2 and 1. After insertion of 5 stack content is 5, 2, 1 then take out 5, 2 and 1. At last, we got the sequence 4, 3, 5, 2 and 1.