Self Studies

Computer Science Test - 10

Result Self Studies

Computer Science Test - 10
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    5 / -1
    Which of the following is a correct syntax to assign an empty list to the identifier named stackone?
    Solution

    Correct option is stackone = list()

    CONCEPT:

    Lists in Python can be created using list() method or by placing the values inside square brackets[], for example

    a=[1,2,3] 

    or we can create list using list() method and then add elements using append() method

    a=list()

    a.append(1)

    a.append(2)

    a.append(3)

     

    In the above question

    Option 2 stackone != list() 

    // here not-equal-to operator is used which is a comparision operator. 

    Option 3 stackone = list[]

    // invalid syntax list[]

    Option 4 stackone = stacklist() 

    //  error as there is no method named stacklist() 

  • Question 2
    5 / -1
    Trying to add an element to a full stack results in an exception called ____________. 
    Solution

    The correct option is overflow

    CONCEPT:

    The basic operations of the stack may hit a special condition or raise an error like:

    Underflow happens when we try to pop (remove) an item from the stack when the stack is already empty. 

    Overflow happens when we try to push an item onto a stack, when the stack is full or out of memory.

     

    Additional Information

    Stack is a linear data structure that follows a last in first out order.

    In python, we can implement a stack using a list data structure by using append() and pop() methods

     

    Basic Operations of Stack:

    • Push: Adding an item to the top of the stack is done using the push operation.
    • Pop: Removing an item from the top of the stack is done using the pop operation.

     

    In python, we can perform

    Push item using the append() method

    Pop top item using the pop() method 

     

  • Question 3
    5 / -1

    While conversion of an Infix notation to its equivalent Prefix/Postfix notation, only ______________ are PUSHED onto the Stack.

    Solution

    The correct Option is operators

    CONCEPT:

    While performing the conversion of an expression, we need to follow some set of rules (operator precedence and associativity rules) to evaluate the result. 

    The position of operators is an important factor to decide the type of expression and to differentiate between the precedence and associativity of two different operators stack data structure is used.

    That is why only operators are pushed onto the stack.

    Example: Converting infix expression to postfix using stack

    Infix: (a+b)-c

    Postfix: ab+c-

    Input Symbol Stack Contents Postfix Expression Explanation
    ( (   If the incoming symbol is '(', push it onto the stack.
    a ( a

    Print operands as they arrive.

    + (+ a If the stack is empty or contains a left Parenthesis on top, push the incoming operator onto the stack.
    b (+ b Print operands as they arrive.
    )   ab+ If the incoming symbol is ')', pop the stack & Print the operators until the left parenthesis is found.
    - - ab+

    If the stack is empty or contains a left Parenthesis on top, push the incoming operator onto the stack.

    c - ab+c Print operands as they arrive.
        ab+c- At the end of the expression, pop & print all operators of the stack.

     

    With the above example, we can say that only operators are PUSHED onto the stack.

  • Question 4
    5 / -1

    Which of the following operation will be performed by pops function on stack "stackname" in the following code?

    def pops(stackname):
          return len(stackname)

    Solution

    Correct option is Returns the size of stack.

    CONCEPT:

    In python def keyword is used to define a function , it is placed before a function name.

    Syntax:

    def function_name: 

         definition statements...

    In the above question pops is a user-defined function that takes a stack named "stackname" as argument

    and returns the length of stack using len() function.

    Example: Let stackname=[1,2,3] is a stack which contains 3 elements

    On calling the pops(stackname)  function, it will return 3 as length of stack.

  • Question 5
    5 / -1
    As these built-in methods append() and pop() insert/delete elements at the _____________ end of the list, hence explicit declaration of TOP is not needed.
    Solution

    The correct option is rightmost

    CONCEPT:

    In python, the append() method adds an element to the end of the list.

    The pop() method removes the item at a given index from the list and returns the removed item.

    If no index value is passed, the default index -1 is passed as an argument (index of the last item) and the last element is removed from the list.

  • Question 6
    5 / -1
    Trying to pop an element from an empty stack results into a special condition ___________.
    Solution

    The correct option is underflow

    CONCEPT:

    Stack is a linear data structure that follows a last in first out order.

    It contains a top pointer that points to the topmost element of the stack.

    The insertion and deletion of items take place from one end only using the top pointer.

    Basic Operations of Stack:

    • Push: Adding an item to the top of the stack is done using the push operation.
    • Pop: Removing an item from the top of the stack is done using the pop operation.
    • IsEmpty: Check if the stack is empty.
    • IsFull: Check if the stack is full.
    • Peek: It returns the item which is on top of the stack without removing it.

     

     

    These basic operations may hit a special condition or raise an error like:

    Underflow happens when we try to pop (remove) an item from the stack when the stack is already empty. 

    Overflow happens when we try to push an item onto a stack, when the stack is full or out of memory.

  • Question 7
    5 / -1

    A ___________ is commonly used data structure to convert an Infix expression into equivalent Prefix/Postfix notation.

    Solution

    The correct Option is Stack

    CONCEPT:

    While performing the conversion of an expression, we need to follow some set of rules (operator precedence and associativity rules) to evaluate the result. 

    The position of operators is an important factor to decide the type of expression and to differentiate between the precedence and associativity of two different operators stack data structure is used.

    Stack data structure has various applications:

    • Expression Conversion
    • Expression Evaluation
    • String Reversal
    • Parenthesis Checking
    • Syntax Parsing

     

    Example of infix to postfix conversion using stack.

    Infix: (2+5)-3

    Postfix: 25+3-

    Input Symbol Stack Contents Postfix Expression Explanation
    ( (   If the incoming symbol is '(', push it onto the stack.
    2 ( 2

    Print operands as they arrive.

    + (+ a If the stack is empty or contains a left Parenthesis on top, push the incoming operator onto the stack.
    5 (+ 5 Print operands as they arrive.
    )   25+ If the incoming symbol is ')', pop the stack & Print the operators until the left parenthesis is found.
    - - 25+

    If the stack is empty or contains a left Parenthesis on top, push the incoming operator onto the stack.

    3 - 25+3 Print operands as they arrive.
        25+3- At the end of the expression, pop & print all operators of the stack.

     

  • Question 8
    5 / -1
    To handle matching of parentheses in an arithmetic expression which data structure is used?
    Solution

    Correct option is Stack

    CONCEPT:

    A Stack is a widely used linear data structure in which insertions and deletions of an element can occur only at one end.

    Stack data structure has various applications:

    • Expression Conversion
    • Expression Evaluation
    • String Reversal
    • Parenthesis Matching
    • Syntax Parsing
  • Question 9
    5 / -1
    A ____________ notation is used for writing an expression in which binary operators are written in between the operands.
    Solution

    Correct option is Infix

    CONCEPT:

    An expression mainly consists of operands, operators, and symbols.

    These must be arranged according to a set of rules so that expressions can be evaluated using the set of rules.

    There are mainly three notations used for writing expression:

    Infix notation: When the operator is written in between the operands it is known as infix notation. Example 2+5

    Prefix notation: When the operator is written before the operands it is known as Prefix notation. Example +25

    Postfix notation: When the operator is written after the operands it is known as Postfix notation. Example 25+

  • Question 10
    5 / -1
    Any arithmetic expression cannot be represented in which of the following notations?
    Solution

    The correct option is Midfix

    CONCEPT:

    There are mainly three notations used for writing expression:

    Infix notation: When the operator is written in between the operands it is known as infix notation. Example 2+5

    Prefix notation: When the operator is written before the operands it is known as Prefix notation. Example +25

    Postfix notation: When the operator is written after the operands it is known as Postfix notation. Example 25+

    But there is no notation like Midfix to represent an expression.

Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now