Flashcards on Stack
Understanding Stack Data Structure: LIFO Principle & Uses
Tap to flip · Swipe to navigate
Stack Data Structure
22 cards
Card 1
Question: What is a data structure in computer science?
Answer: A data structure is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently.
Card 2
Question: What is a stack in computer science?
Answer: A stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection
Card 3
Question: What does LIFO stand for in the context of a stack?
Answer: LIFO stands for Last In, First Out.
Card 4
Question: What does the LIFO principle mean for a stack?
Answer: The last element added to the stack is always the first one to be removed.
Card 5
Question: What are the two primary operations used to interact with a stack?
Answer: Push and Pop.
Card 6
Question: What is the purpose of the `push` operation?
Answer: The `push` operation adds a new element to the top of the stack.
Card 7
Question: What error occurs if you try to `push` an element to a full stack?
Answer: A "stack overflow" error.
Card 8
Question: What is the purpose of the `pop` operation?
Answer: The `pop` operation removes the element currently at the top of the stack.
Card 9
Question: What error occurs if you try to `pop` an element from an empty stack?
Answer: A "stack underflow" error.
Card 10
Question: What is the purpose of the `peek` (or `top`) operation?
Answer: This operation returns the value of the top element without removing it from the stack.