Data Structure
A Data Structure is a way of organizing and storing data in a computer so that it can be
accessed and modified e iciently.
It helps us:
Store data properly
Access data quickly
Insert and delete data easily
Save memory and time
Example
Think of a bookshelf.
If books are arranged properly, you can easily find any book.
If books are scattered randomly, finding one book becomes di icult.
Similarly, a data structure organizes data so it is easy to use
Why Do We Need Data Structures?
Data structures are used to:
Store large amounts of data.
Access data quickly.
Insert and delete data e iciently.
Improve program performance.
Reduce execution time.
Types of Data Structure
Data
Structure
Non-
Linear
Linear
List Stack Queue Tree Graph
Python Built in Data Structure
Dictionary List
Tuple Set
STACK
Principle: LIFO(Last In First Out)
The element inserted last is removed first.
Real-Life Examples
Stack of plates
Browser Back button
Undo operation in MS Word
Books kept one over another
Operations
PUSH
POP
PEEK
IsEmpty(Underflow)
IsFull(Overflow)
Implementation of stack using
List(Python)
PUSH: Inserting elements in the stack
POP: Removing elements from the stack
PEEK: Returns the element that is at the top
of the stack
isEmpty/Under low: This scenario occurs when you try
to remove element from an empty stack
isNull/Over low: This scenario occurs when you try to
insert element on a full stack