0% found this document useful (0 votes)
3 views

Revised STACK in Python XII CS

Uploaded by

snirbhay7800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Revised STACK in Python XII CS

Uploaded by

snirbhay7800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

S T A C K

Know P y thon By tes


w w w. k n o w p y t h o n b y te s . b l o g s p o t . c o m
Mrs. Payal Bhattacharjee, PGT(C.Sc.)
K V No.1 Kanchrapara
KVS-RO(Kolkata)
UNIT-1 (Revised syllabus) XII CS
COMPUTATIONAL THINKING AND PROGRAMMING-II
Chapter: Data Structure: STACK
CONTENTS (LEARNING OUTCOMES)
2022-23

Data-structures:
➢ Lists as covered in Class XI,
➢ Stacks – Push, Pop using a list.
What is a Data Structure?
• Data Structures are a way of organizing, accessing and storing data
more efficiently in a program depending upon the situation. Data
Structures are fundamentals of any programming language around
which a program is built.

Why Data structures in Python is easy?


• Python helps to learn the fundamental of these data structures in a
simpler way as compared to other programming languages.
OPERATIONS ON DATA STRUCTURES
CREATION : Creating/Defining a data structure as per requirement
INSERTION : Adding/Inserting a new element or data
DELETION : Delete/Remove an existing element or data
SEARCHING : Search for the specified element or data
TRAVERSAL : Access / Process all the elements or data
SORTING : Arrange/Organize elements in ascending/descending order
MERGING : Merge/Combine elements of two or more data structures of the same type.
DATA STRUCTURES IN
PYTHON

BUILT-IN DATA USER-DEFINED


STRUCTURES DATA STRUCTURES

LIST TUPLE SETS DICTIONARY

LINKED
STACK QUEUE TREE HASHMAP GRAPH
LIST
DATA STRUCTURE : STACK
STACK: Stack is a linear data structure in which the elements can be added or removed only from one end known as “Top” of the stack.
The discipline of Stack is LIFO (Last In First Out) i.e. element inserted last will be removed first. Or, we can say First In Last Out.
Whereas in a LIST, we can add or delete any element from any position.

REAL LIFE APPLICATION OF STACK


The stack of trays in a cafeteria or plates in a cupboard
Stack of Books or copies
Stack of coins
Stack of Bags / Clothes / Chairs

Some Applications of a stack are:


1.Converting infix to postfix expressions.
2.Undo/Redo button/operation in word processors.
3.Syntaxes in languages are parsed using stacks.
4.It is used in many virtual machines like JVM (Java Virtual Machine).
5.History of visited websites.
6.Message logs and all messages you get are arranged in a stack.
7.Call logs, E-mails, Google photos’ any gallery, YouTube downloads, Notifications ( latest appears first ).
8.Scratch card’s earned after Google pay transaction.
9.Wearing/Removing Bangles, Pile of Dinner Plates, Stacked chairs.
10.Recursion.
11.Used in IDEs to check for proper parentheses matching
12.Media playlist. T o play previous and next song
Operation on Stack:
The basic operations on stack is defined as:
❑ Push- addition of new element on the top of stack.
We are going to implement List as a Stack, so, to add element , we have to use append( ) method of List.
❑ Pop – deletion of element from the top.
We are going to implement List as a Stack, so, to remove the top element , we have to use pop( ) method of List.
❑ isEmpty - indicates whether any elements are stored in the stack or not (underflow).

27 32 45 10
10 45 32 27
27
32 32 32
45 45 45 45 45
10 10 10 10 10 10 10

Empty PUSH PUSH PUSH PUSH POP POP POP POP POP
STACK 10 45 32 27
STACK
UNDERFLOW
Empty Stack
OUTPUT
QUESTION FROM QBANK (THEORY)
Bibliograhy and References
• Google
• Wikipedia
• Quora
• geeksforgeeks
• Book: XII Computer Science
• By Sumita Arora, Dhanpat Rai Publication 2020 Edition
Stay safe. Stay aware. Stay healthy. Stay alert.

You might also like