0% found this document useful (0 votes)
3 views4 pages

Stack

A Data Structure is a method for organizing and storing data efficiently in a computer, allowing for quick access, easy modification, and optimized memory usage. It is essential for managing large data sets and improving program performance. Examples include stacks, queues, trees, and graphs, with stacks operating on a Last In First Out (LIFO) principle.

Uploaded by

mamtawaldia838
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Stack

A Data Structure is a method for organizing and storing data efficiently in a computer, allowing for quick access, easy modification, and optimized memory usage. It is essential for managing large data sets and improving program performance. Examples include stacks, queues, trees, and graphs, with stacks operating on a Last In First Out (LIFO) principle.

Uploaded by

mamtawaldia838
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like