Skip to main content

DSL 11

Data Structure Lab:


Practical B11: 

a) Write a Python program to store roll numbers of student in array who attended training program in random order. Write function for searching whether particular student attended training program or not, using Linear search and Sentinel search. 

b) Write a Python program to store roll numbers of student array who attended training program in sorted order. Write function for searching whether particular student attended training program or not, using Binary search and Fibonacci search

   
 #author:sppucseguru  
   
 A=[]  
 while 'true' :  
  roll= int(input ("Enter roll no. of Students who attended training program "))  
  A.append(roll)  
  res=input ("Do you want to continue ? y or n ")  
  if res=='n':  
   break  
     
 print (A)  
 n=len(A)  
   
   
 #linear search  
 def LSearch():  
  while True:  
   flag=0  
   roll= int(input ("Enter roll no. of Students which you want to check "))  
   for i in range(n):  
    if A[i]==roll:  
     flag=1  
     break  
   if flag==1:  
     print ("Student is present for training program")  
   else:  
     print ("Student is absent for training program")  
   res=input ("Do you want to continue ? y or n ")  
   if res=='y':  
       LSearch()  
   else:  
       print("Search Completed")  
       break  
 
 #Sentinel Search  
def SeSearch(): while True: roll= int(input ("Enter roll no. of Students which you want to check ")) A.append(roll) for i in range(n+1): index=i if A[i]==roll: break if index<n: print ("Student is present for training program") else: print ("Student is absent for training program") res=input ("Do you want to continue ? y or n ") if res=='y': SeSearch() else: print("Search Completed") break #*Remember for binary and fibonacci search we required elements in sorted form* #Binary Search low=0 high=n-1 def BiSearch(): low=0 high=n-1 roll= int(input ("Enter roll no. of Students which you want to check ")) flag=0 while (low<=high) : mid=(high+low)//2 if roll==A[mid]: flag=1 print ("Student is present for training program") break elif roll<A[mid]: high=mid-1 else: low=mid+1 if flag==0: print ("Student is absent for training program") res=input ("Do you want to continue ? y or n ") if res=='y': BiSearch() else: print("Search Completed") # Fibonacci Search def FibSearch(): roll= int(input ("Enter roll no. of Students which you want to check ")) fib1=fib2=1 fib=2 while fib<n: fib2=fib1 fib1=fib fib=fib1+fib2 i=0 offset=-1 flag=0 while fib>1: i=min(offset+fib2,n-1) if A[i]<roll: fib=fib1 fib1=fib2 fib2=fib-fib1 offset=i elif A[i]>roll: fib=fib2 fib1=fib1-fib2 fib2=fib-fib1 else: flag=1 print("Student is present for training program") break if flag==0: print ("Student is absent for training program") res=input ("Do you want to continue ? y or n ") if res=='y': FibSearch() else: print("Search Completed") while True: res=input("""Enter algorithm you want to use a. Linear Search b. Sentinel search c. Binary Search d. Fibonacci Search e. exit\n""") if(res=='a'): LSearch() break elif(res=='b'): SeSearch() break elif(res=='c'): A=sorted(A) BiSearch() break elif(res=='d'): A=sorted(A) FibSearch() break elif(res=='e'): break else: print("Wrong Respond")

Comments

Popular posts from this blog

DSL A1

Hello Friends lets See the first practical of Data Structure Laboratory(DSL) of SPPU Second Year. Some of the students are afraid of coding as it is new to all of us. So we are here to conquer your fear. You will find it easy as it explained by students only. So lets Get into it The first practical of part A is : In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. Write a Python program using functions to compute following: -  a) List of students who play both cricket and badminton  b) List of students who play either cricket or badminton but not both  c) Number of students who play neither cricket nor badminton  d) Number of students who play cricket and football but not badminton.  (Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions)  So most of us know the SET theory in mathematics. The above problem is very easy if you have knowledge about

Bouncing Ball

Group B   Practical 4 a   Problem Statement :   Write a C++ program to implement bouncing ball using sine wave form. Apply the concept of polymorphism. Check Out Code Here  ðŸ‘‡ Outputs :  Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

OOP 6

   Object Oriented Programming Group B - Practical : 6 Problem Statement :  Write C++ program using STL for sorting and searching user defined records such as personal records (Name, DOB, Telephone number etc) using vector container. Check Out Code Here  ðŸ‘‡ Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊