Programming and Data Structures - Stacks

6. Which of the following types of expressions does not require precedence rule when evaluated?

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


7. The five items: A, B, C, D, and E are pushed in a stack, one after the other starting from A.The stack is popped four times and each element is inserted in a queue. Then two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

  • Option : D
  • Explanation : In the queue, elements are deleted from the front (FIFO) and in stacks, elements are popped from the top (LIFO)
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


8. If memory for the run-time stack is only 150 cells(words), how big can N be in Factorial(N) before encounterring stack overflow?

  • Option : C
  • Explanation : Given that, the size of a run-time stack is of 150 cells (words). The arguments to evaluate the factorial are placed on the stack. A function call is made to calculate the factorial. The subroutine is executed for each time the function call is made. Each funcall creates a stack frame of co words (Cells), 2 words for n, 2 words for program counter (PC), and 2 words for some other information. The value of n should be such that, the size of the stack should not exceed 150 cells. If we consider the value of n to be 26, it executes 25 procedure calls each of it with a 6-word stack frame. In this case, the total number of words of stack space would be 150 (6 words × 25 procedure calls = 150) cells. Therefore, the value of n will be 26 is n! before encountering a stack overflow for the stack of size 150 cells (words)
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


9. Using Pop(S1, Item) Push(S1, Item) Read(Item) Print(Item) the variables S1 represents (stack) and Item is given the input file: A,B,C,D,E,F Which stacks are possible:

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


10. Using Pop (S1,Item) ,Push(S1, Item), Getlist(Item), Pop(S2,Item), and the variables S1,S2(stacks with Top1 and Top2) and Item and given the input file: A,B,C,D,E,F Which stack are possible?

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *