DATA STRUCTURE: STACK Flashcards
(36 cards)
a linear data structure that follows the Last-In-First-Out (LIFO)
principle.
STACKS
the last element added to the stack
is the first one to be removed.
• Insertion and deletion allowed only
at one end (top)
STACKS OPERATION
adding an element to the top of the stack
Push (insertion)
STACKS OPERATION
removing the topmost element from the stack
Pop (deletion)
STACKS OPERATION
viewing the topmost element without removing
it
Peek
the stack is full and push operation is
attempted
Overflow state
the stack is empty and we attempt the pop
operation
Underflow state
APPLICATIONS AND USE CASES OF STACKS
Stacks are used to evaluate arithmetic expressions, handle operator precedence, and perform infix-to-postfix
conversion.
Expression Evaluation
APPLICATIONS AND USE CASES OF STACKS
Stacks are used to implement undo functionality in text
editors, software applications, and interactive environments.
Undo Operations
APPLICATIONS AND USE CASES OF STACKS
Stacks are utilized in algorithms that require backtracking,
such as maze-solving and depth-first search.
Backtracking
APPLICATIONS AND USE CASES OF STACKS
Stacks play a role in memory management, particularly in managing activation records during program execution.
Memory Management
a linear data structure that follows the First-In-First-Out (FIFO) principle.
QUEUES
first element added is the first one to be
removed
• It represents a collection of elements in
which elements are added at one end
(rear) and removed from the other end
(front).
Queues
adds an element to the rear (end) of the queue. The
newly added element becomes the last one in the
queue.
queues operations Enqueue (insertion)
removes the element from the front of the queue. The
next element in the queue becomes the new front.
Dequeue (deletion)
view the element at the front of the queue without
removing it.
Peek
A non-linear data structure that consists of nodes
and is connected by edges with a hierarchical organization
TREES
The nodes in a tree are arranged in a each node can have (zero or more
child nodes)
parent-child
relationship
The topmost node in a tree is called the
root node
TERMINOLOGY
Each element in a tree. It contains some data and
may have references to its child nodes. T, S, O, Q, etc. are the nodes of the tree.
Node
Represents a connection between two nodes. It
defines the relationship between a parent node and its
child node. A line connecting the nodes.
Edge
A node that has one or more child nodes. It is
located above its child nodes in the hierarchy.
Parent
A node that has a parent node. It is located below
its parent node in the hierarchy. In a tree, every node except the root node is a child node
Child
A node that does not have any child nodes. It is also known as a terminal node.
Leaf