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 A2

  Write a Python program to store marks scored in subject “Fundamental of Data Structure” by N students in the class. Write functions to compute following:  a) The average score of class  b) Highest score and lowest score of class  c) Count of students who were absent for the test  d) Display mark with highest frequency The Code for above problem is as follows : """ @author: SPPU SE GURU """ total=int(input ("Enter total no. of students in your class ")) pre=int(input("No. of students appeared for FDS exam : ")) U=[] for i in range (total): i=i+1 U.append(i) R=[] for i in range(pre): roll=int(input("Enter Roll no. of students present for test :- ")) R.append(roll) M=[] for i in range(pre): print("Enter Roll no. ",R[i],end=" ") marks=int(input("Marks:- ")) M.append(marks) print("********** Solutions Are as fo...

Printing Name Using Symbols

  This is simple program of printing name using symbols. It just look cool to see. In this program we have simply written print function for different letters. Depending on our input it will take one by one letter and print that letter in the form of symbols. This is just for fun. #Author : SPPU CSE GURU name = input("Enter your name: ") print("\n") print("<><><><><><><><><><><><><><><><><><><><><>\n") for letter in name: letter = letter.upper() if (letter == "A"): print("..@@@@@@..\n..@....@..\n..@@@@@@..\n..@....@..\n..@....@..\n\n") elif (letter == "B"): print("..@@@@@@..\n..@....@..\n..@@@@@...\n..@....@..\n..@@@@@@..\n\n") elif (letter == "C"): print("..@@@@@@..\n..@.......\n..@.......\n..@.......\n..@@@@@@.....

DSL C19

  Department of Computer Engineering has student's club named 'Pinnacle Club'. Students of second, third and final year of department can be granted membership on request. Similarly one may cancel the membership of club. First node is reserved for president of club and last node is reserved for secretary of club. Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name. Write functions to: a) Add and delete the members as well as president or even secretary. b) Compute total number of members of club c) Display members d) Two linked lists exists for two divisions. Concatenate two lists. #include<iostream> using namespace std; struct node{ int PRN; char Name[10]; node *next; }; node *nnode,*npre; char ch; int prn,total=0,choice; class PinClub{ public: node *President,*Secretary; ...