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

Datastructre Class Test

Uploaded by

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

Datastructre Class Test

Uploaded by

Sayara Banu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

G12 - DATASTRUCTRE CLASS TEST 21-07-2024

1. A list, NList contains following record as list elements:


[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following user defined functions in Python to
perform the specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument and pushes a list object containing name of the city and
country, which are not in India and distance is less than 3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays them. Also, the function should display “Stack Empty”
when there are no elements in the stack.

For example: If the nested list contains the following data:


NList=[["New York", "U.S.A.", 11734],
["Naypyidaw", "Myanmar", 3219],
["Dubai", "UAE", 2194],
["London", "England", 6693],
["Gangtok", "India", 1580],
["Columbo", "Sri Lanka", 3405]]
The stack should contain:
['Naypyidaw', 'Myanmar'],
['Dubai', 'UAE'],
['Columbo', 'Sri Lanka']
The output should be:
['Columbo', 'Sri Lanka']
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty

2. 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:
Ditem={"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

3. list contains 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
4. Millions of computer science students have taken a course on algorithms and data structures, typically the second course
after the initial one introducing programming. One of the basic data structures in such a course is the stack. The stack has a
special place in the emergence of computing as a science, as argued by Michael Mahoney, the pioneer of the history of the
theory of computing. The Stack can be used in many computer applications, few are given below:
In Stack, insertion operation is known as Push whereas deletion operation is known as Pop.
Code – 1
def push(Country,N):
Country._________(len(Country),N)) #Statement 1
#Function Calling
Country=[]
C=['Indian', 'USA', 'UK', 'Canada', 'Sri Lanka']
for i in range(0,len(C),________): #Statement 2
push(Country,C[i])
print(Country)
Required Output:
['Indian', 'UK', 'Sri Lanka']

Code - 2
def pop(Country):
if ______________: #Statement 3
return "Under flow"
else:
return Country.________() #Statement 4
#Function Calling
for i in range(len(Country)+1):
print(_______________) #Statement 5
Required Output:
Sri Lanka
UK
India
Under flow
Fill the above statement based on given questions:
i. Identify the suitable code for the blank of statement 1.
a. .append()
b. .insert()
c. .extend()
d. .append(len(Country),N)
ii. Fill the statement 2, to insert the alternate element from Country
list.
a. 3
b. 0
c. -1
d. 2
iii. Fill the statement 3, to check the stack is empty.
a. Country=[]
b. Country.isEmpty()
c. len(country)==0
d. No of the above
iv. Fill the statement 4, to delete an element from the stack.
a. pop(1)
b. pop()
c. del country[1]
d. Country.delete(1)

v. Fill the statement 5, to call the pop function.


a. pop(C)
b. pop(Country)
c. call pop(Country)
d. def pop(Country)

You might also like