python stack mcq | postfix expression mcq

Get latest python stack mcq including postfix expression mcq helpful for cuet computer science and other competitive and entrance exams computer science class 12 stack mcq

  1. Stack follows:

    a. FIFO
    b. LIFO
    c. FILO
    d. LILO

Show Answer

b. LIFO

  1. LIFO stands for

    a. Last IN First Out
    b. Last Insert First Obsolete
    c. Left Insert Forward Off
    d. None of these

Show Answer

a. Last IN First Out

  1. Which of the following is not an example of application of stack in computer science?

    a. Print command from multiple files from same or different computers
    b. Reversing a string
    c. Option of redo/undo in any text/image editor
    d. Back button present in browser to visit web pages last seen

Show Answer

a. Print command from multiple files from same or different computers

  1. The end from which element is added or deleted is called _____ in a stack.
    a. TOP
    b. POP
    c. END
    d. ENQUEUE

Show Answer

a. TOP

  1. Which of the following is not performed on stack?

    a. PUSH
    b. POP
    c. PEEK
    d. None of these

Show Answer

c. PEEK

  1. Adding a new element in a stack is called

    a. Push
    b. Pop
    c. Insert
    d. Enqueue

Show Answer

a. Push

  1. (i) An element can only be removed or added at the end of the stack
    (ii) The removal of element from stack is called POP

    a. (i) True, (ii) False
    b. (i) False, (ii) True
    c. Both are True
    d. Both are False

Show Answer

b. (i) False, (ii) True

  1. Sudhakar wants to make a function ‘push’ to  insert a new item in stack ‘S’ but he is not sure which python method exactly he should use to create so. Help in selecting correct option from followings:

    a. Def push(s, item):
    s.insert(item)
    b. Def push(s, item):
         s.extend(item)
    c. Def push(s, item):
         s.append(item)
    d. All are correct

Show Answer

c. Def push(s, item):
       s.append(item)

  1. Stack is ______ and _________ type of data structure.

    a. Static, linear
    b. Static, non-linear
    c. Dynamic, linear
    d. Dynamic, non-linear

Show Answer

c. Dynamic, linear

  1. Trying to add a new element to a full stack result in an exception which is called

    a. Underflow
    b. Overflow
    c. Peek
    d. None

Show Answer

b. Overflow

  1. Removing an element from stack is referred to

    a. PUSH
    b. POP
    c. ERASE
    d. DEQUEUE

Show Answer

b. POP

  1. python uses _________ data type for creating and managing stack

    a. list
    b. dictionary
    c. tuple
    d. numpy array

Show Answer

a. list

  1. Damru has written a python code to delete an element from stack but he is getting an exception (error) showing ‘underflow’. What could be the reason behind it?

    a. Stack is Full
    b. Stack is not defined
    c. Stack is empty
    d. Stack has only one element

Show Answer

c. Stack is empty

  1. What will this given code do?
    def POP(stack):
          if len(stack)==0:
               print(“Underflow”)
          else:
               stack.pop()

    a. Will delete first element from given stack
    b. Will delete last element from given stack
    c. Will produce error as no index is passed to pop()
    d. Will delete all the elements from given stack

Show Answer

b. Will delete last element from given stack

  1. Pile of book in the library represents

    a. Stack
    b. Queue
    c. Tree
    d. Numpy array

Show Answer

a. Stack

  1. Predict the output of given code:

    R = 0
    Numlist = [3,4,6]
    Numlist.append(2)
    R = R+ numlist.pop()
    R = R + numlist.pop()
    print(R)

    a. 8
    b. 7
    c. 0
    d. Error

Show Answer

a. 8

  1. When the expression A – B is written as AB-. Than it is called as

    a. Infix notation
    b. Prefix notation
    c. Postfix notation
    d. Suffix notation

Show Answer

c. Postfix notation

  1. To convert infix to postfix notation________ data structure is used:

    a. Array
    b. Stack
    c. Queue
    d. String

Show Answer

b. Stack

  1. Select correct output for the following sequence of operation (rightmost no signifies top)
    Push(4), push(7), pop(), push(1), push(3), pop(), push(5)

    a. 47135
    b. 415
    c. 5
    d. 374

Show Answer

b. 415

  1. Consider an empty stack of integers. Let the numbers 4,5,6,7,8 be pushed on to this stack only in the order they appeared from left to right. Let P indicates a PUSH and Q indicates a POP operation. What sequence of operations should be performed on stack in order to get the output as 548.

    a. PPPXPPXX
    b. PPXPPPXX
    c. PPXXPPPX
    d. PXXPPXPX

Show Answer

c. PPXXPPPX

  1. Consider an empty stack of integers. Let the numbers 2,3,4,5,6,7  be pushed on to this stack only in the order they appeared from left to right. Let P indicates a PUSH and Q indicates a POP operation. What sequence of operations should be performed on stack in order to get the output as 35762.

    a. PPPXPXPPXXXX
    b. PPXXPXPPPXXX
    c. PPXPPXPPXXXX
    d. PXPXPPXPPXXX

Show Answer

c. PPXPPXPPXXXX

  1. Translate following infix expression to its equivalent postfix expression. (↑ denotes exponentiation and / integer division)
    (A+B↑D)/(E-F)+G

    a. ABD↑+EF-G+/
    b. ABD↑+EF-/G+
    c. AB+D↑EF-/G+
    d. None of these

Show Answer

b. ABD↑+EF-/G+

  1. For a given stack of 5 elements, when will underflow occur?

    a. It will occur when stack will be having all 5 elements and you try to insert a new element
    b. It will occur when all the elements will have been deleted from the stack and no more elements could be deleted.
    c. It will occur when only one element will be left after deleting all elements and you try to delete that last element.
    d. You try to delete element that does not exist in stack

Show Answer

b. It will occur when all the elements will have been deleted from the stack and no more elements could be deleted.

  1. Evaluate following postfix expression to show result. Given A = 3, B = 4, C=2, D = 4
    AB+DC/-

    a. 4
    b. 5
    c. 6
    d. 0

Show Answer

b. 5

  1. Evaluate the following postfix expression to show result:
    10 20 + 25 15 – * 30 +

    a. 330
    b. 300
    c. 70
    d. 0

Show Answer

a. 330

  1. Write equivalent postfix expression for the infix expression
    A + B – D/X

    a. AB+D-X/
    b. ABD- + X/
    c. AB+DX/-
    d. BD-A+X/

Show Answer

c. AB+DX/-

  1. Give postfix for the following expression:
    A*(B + (C + D) * (E + F)/G) * H

    a. ABCD+EF+*G/+*H*
    b. ABCD+EF+G/*+*H*
    c. ABCD+*EF+G/+*H*
    d. ABCD+*EF+G/*H*+

Show Answer

a. ABCD+EF+*G/+*H*

  1. Convert ((A + B)* C/D + E ^ F)/G into postfix notation

    a. AB+CD/*EF^+G/
    b. AB+C*D/EF^+G/
    c. AB+C*D/EF^+G/
    d. None of these

Show Answer

c. AB+C*D/EF^+G/

  1. Give postfix expression for following infix expression:
    NOT A OR NOT B NOT C

    a. A NOT B NOT C NOT OR AND
    b. A NOT B NOT OR C NOT AND
    c. A NOT OR B NOT AND C NOT
    d. A NOT B NOT C NOT AND OR

Show Answer

d. A NOT B NOT C NOT AND OR

  1. Evaluate following postfix expression and display result:
    20 45 + 20 10 – 15 + *

    a. 1625
    b. 665
    c. 825
    d. None

Show Answer

a. 1625

  1. What value should be placed at blank space in following postfix expression to get desired result:
    5 3 * 7 1 – * __ –   =  80

    a. 10
    b. 12
    c. 8
    d. 6

Show Answer

a. 10

  1. If the sequence of operations performed on stack is
    Push(1) push(2) pop() push(3) pop() push(4) push(5) pop() pop()
    Than the output would be

    a. 3
    b. 2
    c. 1
    d. 14

Show Answer

c. 1

  1. For given stack containing 5 elements as
    Stack : RAM_ _
    Assertion: R can not be deleted before M
    Reason: As M has been inserted after R and follows LIFO rule

    a. A is correct, R is incorrect
    b. A is incorrect, R is correct
    c. Both A and R is correct and R is correct explanation of A
    d. Both A and R is correct but R is not correct explanation of A

Show Answer

c. Both A and R is correct and R is correct explanation of A

  1. Consider the following postfix expression of stack. The required output is 5. Select the missing operators.
    4,6,4,+,10,__, __

    a. -,/
    b. /.-
    c. +,/
    d. /, +

Show Answer

both c. +,/ and d./,+

5 thoughts on “python stack mcq | postfix expression mcq”

  1. Krishna Kumar Gupta

    Sir, question no. 15 needs to be fixed:
    ERRORS;
    [ r is not defined, list uses “,” for value separation, print(R) is also not written there]

Leave a Comment

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

error: Content is protected !!