SlideShare a Scribd company logo
1 of 81
DATA STRUCTURE
Data structure
Data Structure is a way to create a logical structure in
the memory so that the storage of numerous data value
could be managed using minimum space.
It helps in fast accessing of data during the execution of
the program.
Data structure is a storage that is used to store and
organize data. It is a way of arranging data on a computer
so that it can be accessed and updated efficiently
Simple Data Structure
The simplest data structure is the one-dimensional (linear) array,
in which stored elements are numbered with consecutive integers
and contents are accessed by these numbers.
An array is a collection of items of same data type stored at
contiguous memory locations.
Declaration of array
a=array[10]
Compound Data Structure
The simple data structure can be combining in various
ways to form more complex data structure called
Compound Data Structure.
They are classified into two types:
Linear Data Structures
A structure that contains those values stored in
sequentially or linearly is called linear Data Structure.
Eg. Stack
Queue
Linked list
List
Tuple
Non-Linear Data Structures:
A non Linear data structure does not store data linearly or
sequentially.
Eg: Tree
Graphs
Tree
Trees are hierarchical data structures, usually built as a top-
down structure where each node contains a unique value
and contains references to child nodes.
Tree is a non linear data structure resembles as actual tree of
our environment that generates from root & ultimately
terminates into the leaves.
The two common types of trees are:
Binary Tree:
Binary Tree is a tree Structure which each node should have
at most two branches.
Binary Searched Tree:
A binary searched tree is a tree structure in which each left node
value is smaller and each right value is greater than parent node.
Stack
Stacks in Data Structures is a linear type of data
structure that follows the LIFO (Last-In-First-Out)
principle and allows insertion and deletion operations
from one end of the stack data structure, that is top.
This is a linear data structure which facilitates the
concepts of LIFO (Last In First Out) and FILO
(First In Last Out)
Stack Mechanism
First Insert Last delete
Note: Insertion and deletion from one end
LIFO Principle of Stack
In programming terms, putting an item on top of the
stack is called push and removing an item is called pop
Operation in stack
There are mainly two types of operation that can be
done with stack.
Insertion of Elements(PUSH)
Deletion of elements (POP)
Peek (Top Element)
Display
Functionality
Program Implementation of stack Using List
def push(a,val):
a.append(val)
def popitems(a):
print("pop item is", a.pop())
def peek(a):
i=len(a)-1
print("The top element is ",a[i])
def display(a):
for i in range(len(a)-1,-1,-1):
print(a[i])
a=[]
while True:
choice=int(input("1.Pushn2.POP
n3.Peekn4.Displayn5.Enter
your Choice"))
if choice==1:
val=int(input("Enter value to insert in stack"))
push(a,val)
elif choice==2:
if len(a)==0:
print("Stack Underflow")
else:
popitems(a)
elif choice==3:
if len(a)==0:
print("Stack Underflow")
else:
peek(a)
elif choice==4:
if len(a)==0:
print("Stack Underflow")
else:
display(a)
SOLUTION
Q. Vedika has created a dictionary containing names and marks
as key-value pairs of 5 students. Write a program, with separate
user-defined functions to perform the following operations:
Push the keys (name of the student) of the dictionary into a
stack, where the corresponding value (marks) is greater than 70.
Pop and display the content of the stack.
The dictionary should be as follows:
d={“Ramesh”:58, “Umesh”:78, “Vishal”:90, “Khushi”:60, “Ishika”:95}
Then the output will be: Umesh Vishal Ishika
def push(stack,i):
stack.append(i)
def pop():
if stack!=[]:
return stack.pop()
else:
return None
N=["UMESH","RAJESH","TOM","ALI","DINESH"]
stack=[]
for i in N:
if len(i)<=5:
push(stack,i)
while True:
if stack!=[]:
print(stack.pop(),end=" ")
else:
break
Q. Raghav has created a vocabulary list. You need to help him
create a program with separate user defined functions to
perform the following operation based on this list.
Traverse the content of the list and push the entries having less
than or equal to 5 characters into a stack.
Pop and display the content of stack.
For example if the sample content of the list is a follow.
N= ["UMESH","RAJESH","TOM","ANS"]
The sample output of the code should be
ANS TOM UMESH [CBSE 2021]
(a) A list contains the following record of customer: [Customer_name, Room
Type]
Write the following user-defined functions to perform given operations on the
stack named ‘ Hotel’:
i) Push_Cust () – To Push customers names of those customers who are staying
in Delux’ Room Type.
ii) Pop_Cust ()- To Pop the names of customers from the stack and display
them. Also, display “Underflow” when there are no customers in the stack.
For example:
If the lists with customer details are as follows:
[“siddarth”, “Delux”]
[“Rahul”, “Standard”]
[“Jerry”, “Delux”]
The stack should contain
Jerry
Siddharth
The output should be:
Jerry
Siddharth
Underflow
Write a function in python, MakePush(Package) and
MakePop(Package) to add a new Package and delete a Package
from a List of Package Description, considering them to act as
push and pop operations of the Stack data structure.
def MakePush(Package):
a=int(input("enter package title : "))
Package.append(a)
def MakePop(Package):
if (Package==[]):
print( "Stack empty")
else:
print ("Deleted element:",Package.pop())
travel=[]
def Push_element(NList):
for L in NList:
if L[1]!="India" and L[2]<3500:
travel.append([L[0],L[1]])
def Pop(travel):
while len(travel):
print(travel.pop())
else:
print("Stack empty")
NList=[["New York", "U.S.A.", 11734],["Naypyidaw", "Myanmar", 3219],
["Dubai", "UAE", 2194],["London", "England", 6693],["Gangtok", "India", 1580],["Columbo", "Sri
Lanka", 3405]]
Push_element(NList)
Pop(travel)
A list contains following record of a customer:
[Customer_name, Phone_number, City]
Write the following user defined functions to perform given operations on the
stack named ‘status’:
Push_element() – To Push an object containing name and Phone number of
customers who live in Goa to the stack
Pop_element() – To Pop the objects from the stack and display them. Also,
display “Stack Empty” when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”]
[“Murugan”,”77777777777”,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]
The stack should contain
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
The output should be:
[“Ashmit”,”1010101010”]
[“Gurdas”,”9999999999”]
Stack Empty
Write a function in Python, Push (SItem)
where , SItem is a dictionary containing the details of stationary
items– {Sname:price}.
The function should push the names of those items in the stack
who have price greater than 75. Also display the count of elements
pushed into the stack.
For example:
If the dictionary contains the following
data:
Sitem={“Pen”:106,”Pencil”:59,”Notebook”:80,”Eraser”:25}
The stack should contain
Notebook
Pen
The output should be:
The count of elements in the stack is 2
def Push(SItem):
STACK=[]
for i in SItem:
if SItem[i]>75:
STACK.append(i)
print("The count of elements in the stack is ",len(STACK))
SItem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
Push(SItem)
-------------------------------------------------------------------------------------------------------
BCCI has created a dictionary containing top players and their runs
as key value pairs of cricket team. Write a program, with
separate user defined functions to perform the following operations:
Push the keys (name of the players) of the dictionary into a stack,
where the corresponding value(runs) is greater than 49.
•Pop and display the content of the stack. For example: If the sample
content of the dictionary is as follows:
SCORE= {"KAPIL":40, "SACHIN":55,"SAURAV":80, "RAHUL":35,
"YUVRAJ":110}
The output from the program should be: YUVRAJ SAURAV SACHIN
SCORE={"KAPIL":40,"SACHIN":55 , "SAURAV":80,"RAHUL":35, "YUVRAJ":110}
def PUSH(STACK,R):
STACK.append(R)
def POP(S):
if STACK!=[]:
return STACK.pop()
else:
return None
STACK=[ ]
for k in SCORE:
if SCORE[k]>49:
PUSH(STACK,k)
while True:
if STACK!=[]:
print(POP(STACK),end=" ")
else:
break
Write the definition of a user defined function Push3_5(N) which
accepts a list of integers in a parameter N and pushes all those
integers which are divisible by 3 or divisible by 5 from the list N into
a list named Only3_5.
● Write a program in Python to input 5 integers into a list named
NUM.
The program should then use the function Push3_5() to create the
stack of the list Only3_5. There after pop each integer from the list
Only3_5 and display the popped value. When the list is empty,
display the message "Stack Empty".
For example: If the integers input into the list NUM are:
[10,6,14,18,30]
Then the stack Only3_5 should store [10,6,18,30]
And the output should be displayed as
30 18 6 10 Stack Empty
Prateek has created a list arr with some elements. Help
him to create a user-defined function to perform the
following tasks:
• Create a stack after checking the elements if it is even
then multiply by 2 and if the element is odd, then multiply
it by 3.
• Pop and display the contents of the stack.
Sample Input Data of the list
arr = [2,3,4,5,6,7,8,9,10]
Output stack:
NewSt = [4, 9, 8, 15,12, 21, 16, 27,20]
def push(NewSt,arr):
for i in arr:
if i%2==0:
NewSt.append(i*2)
else:
NewSt.append(i*3)
print(NewSt)
def pop(st):
if st==[]:
print('Underflow')
else:
return st.pop()
arr=[2,3,4,5,6,7,8,9,10]
NewSt=[]
push(NewSt,arr)
while True:
if NewSt!=[]:
print(pop(NewSt),end=" ")
else:
break
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx
DATA STRUCTURE CLASS 12 .pptx

More Related Content

Similar to DATA STRUCTURE CLASS 12 .pptx

ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxjeyel85227
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189Mahmoud Samir Fayed
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxParveenShaik21
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILEAnushka Rai
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using PythonNishantKumar1179
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptxrani marri
 
pandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptxpandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptxvallarasu200364
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdfpallavi953613
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196Mahmoud Samir Fayed
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .pptpoonamsngr
 

Similar to DATA STRUCTURE CLASS 12 .pptx (20)

ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
02 arrays
02 arrays02 arrays
02 arrays
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILECOMPUTER SCIENCE CLASS 12 PRACTICAL FILE
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
pandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptxpandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptx
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 
Array assignment
Array assignmentArray assignment
Array assignment
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
 
1597380885789.ppt
1597380885789.ppt1597380885789.ppt
1597380885789.ppt
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 

DATA STRUCTURE CLASS 12 .pptx

  • 1. DATA STRUCTURE Data structure Data Structure is a way to create a logical structure in the memory so that the storage of numerous data value could be managed using minimum space. It helps in fast accessing of data during the execution of the program. Data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently
  • 2.
  • 3. Simple Data Structure The simplest data structure is the one-dimensional (linear) array, in which stored elements are numbered with consecutive integers and contents are accessed by these numbers. An array is a collection of items of same data type stored at contiguous memory locations. Declaration of array a=array[10]
  • 4. Compound Data Structure The simple data structure can be combining in various ways to form more complex data structure called Compound Data Structure. They are classified into two types: Linear Data Structures A structure that contains those values stored in sequentially or linearly is called linear Data Structure. Eg. Stack Queue Linked list List Tuple
  • 5. Non-Linear Data Structures: A non Linear data structure does not store data linearly or sequentially. Eg: Tree Graphs Tree Trees are hierarchical data structures, usually built as a top- down structure where each node contains a unique value and contains references to child nodes. Tree is a non linear data structure resembles as actual tree of our environment that generates from root & ultimately terminates into the leaves.
  • 6.
  • 7. The two common types of trees are: Binary Tree: Binary Tree is a tree Structure which each node should have at most two branches.
  • 8. Binary Searched Tree: A binary searched tree is a tree structure in which each left node value is smaller and each right value is greater than parent node.
  • 9. Stack Stacks in Data Structures is a linear type of data structure that follows the LIFO (Last-In-First-Out) principle and allows insertion and deletion operations from one end of the stack data structure, that is top. This is a linear data structure which facilitates the concepts of LIFO (Last In First Out) and FILO (First In Last Out)
  • 10. Stack Mechanism First Insert Last delete Note: Insertion and deletion from one end
  • 11. LIFO Principle of Stack In programming terms, putting an item on top of the stack is called push and removing an item is called pop Operation in stack There are mainly two types of operation that can be done with stack. Insertion of Elements(PUSH) Deletion of elements (POP) Peek (Top Element) Display
  • 13.
  • 14. Program Implementation of stack Using List def push(a,val): a.append(val) def popitems(a): print("pop item is", a.pop()) def peek(a): i=len(a)-1 print("The top element is ",a[i]) def display(a): for i in range(len(a)-1,-1,-1): print(a[i]) a=[] while True: choice=int(input("1.Pushn2.POP n3.Peekn4.Displayn5.Enter your Choice")) if choice==1: val=int(input("Enter value to insert in stack")) push(a,val) elif choice==2: if len(a)==0: print("Stack Underflow") else: popitems(a) elif choice==3: if len(a)==0: print("Stack Underflow") else: peek(a) elif choice==4: if len(a)==0: print("Stack Underflow") else: display(a)
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 28. Q. Vedika has created a dictionary containing names and marks as key-value pairs of 5 students. Write a program, with separate user-defined functions to perform the following operations: Push the keys (name of the student) of the dictionary into a stack, where the corresponding value (marks) is greater than 70. Pop and display the content of the stack. The dictionary should be as follows: d={“Ramesh”:58, “Umesh”:78, “Vishal”:90, “Khushi”:60, “Ishika”:95} Then the output will be: Umesh Vishal Ishika
  • 29. def push(stack,i): stack.append(i) def pop(): if stack!=[]: return stack.pop() else: return None N=["UMESH","RAJESH","TOM","ALI","DINESH"] stack=[] for i in N: if len(i)<=5: push(stack,i) while True: if stack!=[]: print(stack.pop(),end=" ") else: break
  • 30.
  • 31. Q. Raghav has created a vocabulary list. You need to help him create a program with separate user defined functions to perform the following operation based on this list. Traverse the content of the list and push the entries having less than or equal to 5 characters into a stack. Pop and display the content of stack. For example if the sample content of the list is a follow. N= ["UMESH","RAJESH","TOM","ANS"] The sample output of the code should be ANS TOM UMESH [CBSE 2021]
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. (a) A list contains the following record of customer: [Customer_name, Room Type] Write the following user-defined functions to perform given operations on the stack named ‘ Hotel’: i) Push_Cust () – To Push customers names of those customers who are staying in Delux’ Room Type. ii) Pop_Cust ()- To Pop the names of customers from the stack and display them. Also, display “Underflow” when there are no customers in the stack. For example: If the lists with customer details are as follows: [“siddarth”, “Delux”] [“Rahul”, “Standard”] [“Jerry”, “Delux”] The stack should contain Jerry Siddharth The output should be: Jerry Siddharth Underflow
  • 39.
  • 40.
  • 41. Write a function in python, MakePush(Package) and MakePop(Package) to add a new Package and delete a Package from a List of Package Description, considering them to act as push and pop operations of the Stack data structure. def MakePush(Package): a=int(input("enter package title : ")) Package.append(a) def MakePop(Package): if (Package==[]): print( "Stack empty") else: print ("Deleted element:",Package.pop())
  • 42.
  • 43.
  • 44.
  • 45. travel=[] def Push_element(NList): for L in NList: if L[1]!="India" and L[2]<3500: travel.append([L[0],L[1]]) def Pop(travel): while len(travel): print(travel.pop()) else: print("Stack empty") NList=[["New York", "U.S.A.", 11734],["Naypyidaw", "Myanmar", 3219], ["Dubai", "UAE", 2194],["London", "England", 6693],["Gangtok", "India", 1580],["Columbo", "Sri Lanka", 3405]] Push_element(NList) Pop(travel)
  • 46.
  • 47. A list contains following record of a customer: [Customer_name, Phone_number, City] Write the following user defined functions to perform given operations on the stack named ‘status’: Push_element() – To Push an object containing name and Phone number of customers who live in Goa to the stack Pop_element() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack. For example: If the lists of customer details are: [“Gurdas”, “99999999999”,”Goa”] [“Julee”, “8888888888”,”Mumbai”] [“Murugan”,”77777777777”,”Cochin”] [“Ashmit”, “1010101010”,”Goa”] The stack should contain [“Ashmit”,”1010101010”] [“Gurdas”,”9999999999”] The output should be: [“Ashmit”,”1010101010”] [“Gurdas”,”9999999999”] Stack Empty
  • 48.
  • 49. Write a function in Python, Push (SItem) where , SItem is a dictionary containing the details of stationary items– {Sname:price}. The function should push the names of those items in the stack who have price greater than 75. Also display the count of elements pushed into the stack. For example: If the dictionary contains the following data: Sitem={“Pen”:106,”Pencil”:59,”Notebook”:80,”Eraser”:25} The stack should contain Notebook Pen The output should be: The count of elements in the stack is 2
  • 50. def Push(SItem): STACK=[] for i in SItem: if SItem[i]>75: STACK.append(i) print("The count of elements in the stack is ",len(STACK)) SItem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25} Push(SItem) -------------------------------------------------------------------------------------------------------
  • 51. BCCI has created a dictionary containing top players and their runs as key value pairs of cricket team. Write a program, with separate user defined functions to perform the following operations: Push the keys (name of the players) of the dictionary into a stack, where the corresponding value(runs) is greater than 49. •Pop and display the content of the stack. For example: If the sample content of the dictionary is as follows: SCORE= {"KAPIL":40, "SACHIN":55,"SAURAV":80, "RAHUL":35, "YUVRAJ":110} The output from the program should be: YUVRAJ SAURAV SACHIN
  • 52. SCORE={"KAPIL":40,"SACHIN":55 , "SAURAV":80,"RAHUL":35, "YUVRAJ":110} def PUSH(STACK,R): STACK.append(R) def POP(S): if STACK!=[]: return STACK.pop() else: return None STACK=[ ] for k in SCORE: if SCORE[k]>49: PUSH(STACK,k) while True: if STACK!=[]: print(POP(STACK),end=" ") else: break
  • 53.
  • 54. Write the definition of a user defined function Push3_5(N) which accepts a list of integers in a parameter N and pushes all those integers which are divisible by 3 or divisible by 5 from the list N into a list named Only3_5. ● Write a program in Python to input 5 integers into a list named NUM. The program should then use the function Push3_5() to create the stack of the list Only3_5. There after pop each integer from the list Only3_5 and display the popped value. When the list is empty, display the message "Stack Empty". For example: If the integers input into the list NUM are: [10,6,14,18,30] Then the stack Only3_5 should store [10,6,18,30] And the output should be displayed as 30 18 6 10 Stack Empty
  • 55.
  • 56. Prateek has created a list arr with some elements. Help him to create a user-defined function to perform the following tasks: • Create a stack after checking the elements if it is even then multiply by 2 and if the element is odd, then multiply it by 3. • Pop and display the contents of the stack. Sample Input Data of the list arr = [2,3,4,5,6,7,8,9,10] Output stack: NewSt = [4, 9, 8, 15,12, 21, 16, 27,20]
  • 57.
  • 58. def push(NewSt,arr): for i in arr: if i%2==0: NewSt.append(i*2) else: NewSt.append(i*3) print(NewSt) def pop(st): if st==[]: print('Underflow') else: return st.pop() arr=[2,3,4,5,6,7,8,9,10] NewSt=[] push(NewSt,arr) while True: if NewSt!=[]: print(pop(NewSt),end=" ") else: break