Exit Chapter 06 ยท ๐Ÿ“ฆ Data Structures (Stack) โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 25 0 correct so far

๐Ÿ“ฆ Data Structures (Stack) Quiz

Q1.

What does LIFO stand for in the context of a Stack data structure?

Explanation

LIFO stands for Last In First Out, meaning the last element added to the stack is the first one to be removed.

Q2.

Which operation is used to insert an element into a Stack?

Explanation

The operation used to insert an element into a stack is called 'Push'.

Q3.

Which operation is used to remove an element from a Stack?

Explanation

The operation used to remove an element from the top of the stack is called 'Pop'.

Q4.

What is the condition called when we try to POP an element from an empty stack?

Explanation

Attempting to remove an element from an empty stack results in an Underflow condition.

Q5.

What is the condition called when we try to PUSH an element into a stack that is already full?

Explanation

Attempting to add an element to a stack that has reached its maximum capacity results in an Overflow condition.

Q6.

Which built-in Python list method is commonly used to implement the PUSH operation of a stack?

Explanation

In Python, the list method append() adds an element to the end of the list, acting identically to a stack PUSH operation.

Q7.

Which built-in Python list method is used to implement the POP operation of a stack?

Explanation

The list method pop() removes and returns the last element of the list, identical to a stack POP operation.

Q8.

How do you check if a Python list used as a stack is empty?

Explanation

You can check if a Python list is empty by verifying its length with len(stack) == 0.

Q9.

Which variable is traditionally used to keep track of the index of the highest element in a stack?

Explanation

The 'TOP' variable (or pointer) is used to track the most recently added element in a stack.

Q10.

If an initial stack st = [] undergoes st.append(10), st.append(20), and st.pop(), what is the final state of the stack?

Explanation

10 is pushed, then 20 is pushed. The pop() operation removes the last element (20), leaving [10].

Q11.

What is the primary application of a stack in modern text editors?

Explanation

Stacks are heavily used for the Undo/Redo mechanism. The most recent action is popped first to undo it.

Q12.

Which of the following expression formats places the operator AFTER its operands?

Explanation

Postfix expression (also known as Reverse Polish Notation) places the operator after its operands (e.g., AB+).

Q13.

What is the Postfix equivalent of the Infix expression A + B?

Explanation

In Postfix notation, the operands come first followed by the operator: AB+.

Q14.

When converting an Infix expression to Postfix using a stack, what is primarily stored in the stack?

Explanation

During Infix to Postfix conversion, the stack is used to temporarily hold Operators based on their precedence.

Q15.

In expression evaluation, what is the order of precedence from highest to lowest?

Explanation

The order of precedence is Parentheses (), followed by Exponentiation (^ or **), Multiplication/Division (*, /), and finally Addition/Subtraction (+, -).

Q16.

How can you view the TOP element of a stack st without removing it in Python?

Explanation

In Python lists, st[-1] accesses the last element (the TOP of the stack) without removing it. This is commonly known as the PEEK operation.

Q17.

Which of the following is NOT an application of a Stack?

Explanation

Task scheduling (First Come First Serve) uses a Queue (FIFO), not a Stack. Stacks are used for evaluating expressions, balancing parentheses, and reversing strings.

Q18.

What happens if we execute stack.pop() on a Python list stack = []?

Explanation

Python lists raise an IndexError: pop from empty list when trying to pop an empty list. We usually catch this to print an 'Underflow' message.

Q19.

What is the Prefix equivalent of the Infix expression (X + Y) * Z?

Explanation

First, convert (X + Y) to +XY. Then multiply by Z: * goes to the front of the entire expression, resulting in *+XYZ.

Q20.

A stack is implemented as a list s = [10, 20, 30]. What is the value of TOP if elements are added to the end of the list?

Explanation

The elements are at indices 0, 1, and 2. The top element is 30, which is at index 2. Thus, TOP = 2.

Q21.

What is the time complexity of pushing an element onto a stack implemented using a Python list (ignoring dynamic resizing)?

Explanation

The append() operation on a Python list generally takes O(1) constant time.

Q22.

What is the time complexity of popping an element from the TOP of a stack implemented using a Python list?

Explanation

The pop() operation without arguments removes the last element of the list, which takes O(1) constant time.

Q23.

When checking for balanced parentheses using a stack, what do we do when we encounter a closing bracket like '}'?

Explanation

In a parenthesis matching algorithm, closing brackets trigger a POP operation. The popped bracket must match the opening type of the closing bracket.

Q24.

Evaluate the Postfix expression: 4 2 + 5 *

Explanation

First: 4 + 2 = 6. The expression becomes 6 5 *. Then: 6 * 5 = 30.

Q25.

A web browser's 'Back' button is a classic example of which data structure?

Explanation

The browser history operates on a Stack principle. When you visit a new page, it is PUSHED onto the history stack. Pressing 'Back' POPS the current page to reveal the previous one.