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)
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
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)
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