Posts

Showing posts from August, 2020

Ternary Search

  # Q13. Write A Python Program To Maintain Club Members, Sort On Roll Numbers InAscending Order. # Write Function 'Ternary Search' To Search whether A Particular Student Is AMember Of Club Or Not. # Ternary Search Is Modified Binary Search That Divides Array Into 3 HalvesInstead Of 2. # Ternary Search arr = [] def TakeInput (): num = int ( input ( "Enter The Number Of Students \n " )) for i in range (num): students = int ( input ( f"Enter The Roll No Of Student { i + 1 }\n " )) arr.append(students) print ( " \n Array Of Total Students =" , arr, " \n " ) def bubbleSort (array): n = len (array) print ( " \n Unsorted Array Of Total Students =" , arr) flag = 0 for i in range (n): for j in range (n - i - 1 ): if array[j] > array[j + 1 ]: array[j], array[j + 1 ] = array[j + 1 ], array[j] flag = 1 if flag == 0 : ...

Selection Sort

# Selection Sort def selectionSort (array, n): for i in range (n - 1 ): for j in range (i + 1 , n): if array[j] < array[i]: array[j], array[i] = array[i], array[j] print ( "Sorted Array Of Percentage Of Students =" , array) size = int ( input ( "Enter The Number Of Students \n " )) arr = [] for i in range (size): userinput = int ( input ( f"Enter The Percentege Of Student { i + 1 }\n " )) arr.append(userinput) print ( " \n Unsorted Array Of Percentage Of Students =" , arr) selectionSort(arr, size) # Output # Enter The Number Of Students # 10 # Enter The Percentege Of Student 1 # 82 # Enter The Percentege Of Student 2 # 92 # Enter The Percentege Of Student 3 # 89 # Enter The Percentege Of Student 4 # 75 # Enter The Percentege Of Student 5 # 74 # Enter The Percentege Of Student 6 # 65 # Enter The Percentege Of Student 7 # 68 # Enter The Percentege Of Student 8 # 85 # Enter The Percentege Of Stu...

Quick Sort With Pivot At Random Element

  # Q.14 Write A Python Program To Store First Year Percentage Of Students In Array. # Write Function For Sorting Array Of Floating Point Numbers In Ascending Order Using Quick # Sort And Display Top Five Scores # Quick Sort import random def partition (arr, left, right): randint = random.randint(left, right) arr[randint], arr[right] = arr[right], arr[randint] pivot = arr[right] first = left last = right - 1 while True : while first <= last and arr[first] <= pivot: first = first + 1 while first <= last and arr[last] >= pivot: last = last - 1 if first < last: arr[first], arr[last] = arr[last], arr[first] else : break arr[right], arr[first] = arr[first], arr[right] return first def quickSort (arr, left, right): if left < right: pivotindex = partition(arr, left, right) quickSort(arr, left, pivotindex - 1 ) quickSort(arr...

Quick Sort With Pivot At Last Element

# Q.14 Write A Python Program To Store First Year Percentage Of Students In Array. # Write Function For Sorting Array Of Floating Point Numbers In Ascending Order Using Quick # Sort And Display Top Five Scores # Quick Sort def partition (arr, left, right): pivot = arr[right] first = left last = right - 1 while True : while first <= last and arr[first] <= pivot: first = first + 1 while first <= last and arr[last] >= pivot: last = last - 1 if first < last: arr[first], arr[last] = arr[last], arr[first] else : break arr[right], arr[first] = arr[first], arr[right] return first def quickSort (arr, left, right): if left < right: pivotindex = partition(arr, left, right) quickSort(arr, left, pivotindex - 1 ) quickSort(arr, pivotindex + 1 , right) return arr if __name__ == '__main__' : try : num = int ( input ( ...

Quick Sort With Pivot At First Element

  # Q.14 Write A Python Program To Store First Year Percentage Of Students In Array. # Write Function For Sorting Array Of Floating Point Numbers In Ascending Order Using Quick # Sort And Display Top Five Scores # Quick Sort def partition (arr, left, right): pivot = arr[left] first = left + 1 last = right while True : while first <= last and arr[first] <= pivot: first = first + 1 while first <= last and arr[last] >= pivot: last = last - 1 if first < last: arr[first], arr[last] = arr[last], arr[first] else : break arr[left], arr[last] = arr[last], arr[left] return last def quickSort (arr, left, right): if left < right: pivotindex = partition(arr, left, right) quickSort(arr, left, pivotindex - 1 ) quickSort(arr, pivotindex + 1 , right) return arr if __name__ == '__main__' : try : num = int ( input ( "E...

Set Operation

  # 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. # A | B - Union Of Two Sets A And B # A & B - Intersection Of Two Sets A And B # A - B - Difference Of Two Sets A And B # A ^ B - Symmetric Difference Of Two Sets A And B try : userinput = int ( input ( "Enter Total Numbers Students In Class - " )) totalstud = [] for numc in range (userinput): rollno = int ( input ( f"Enter Roll No. Of Student { numc + 1 } - " )) totalstud.append(rollno) print ( "List Of Roll No Of Students In The Class -" , totalstud, " \n " ) userinp1 = int ( input ( "Enter The Number Of Students Who Play Cricket - " )) cricket = [...

Python Program To Store Marks

  # Group A - 2 # 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 try : list1 = [] userinput1 = int ( input ( "Enter The Numbers Of Students Who Attended The Test - " )) for k in range (userinput1): marks = int ( input ( f"Enter The Marks Of Student { k + 1 } - " )) list1.append(marks) def average (list1): sum = 0 counter = 0 for marks in list1: sum = sum + marks counter = counter + 1 avg = sum / counter print ( " \n Total Score =" , sum) print ( "Average Score Of Class Is =" , avg, "%" , " \n " ) average(list1) def maximum (list1): ma...

Currency.txt

Euro 0.848884 1.178017 British Pound 0.764894 1.307371 Indian Rupee 74.918880 0.013348 Australian Dollar 1.397888 0.715365 Canadian Dollar 1.319703 0.757746 Singapore Dollar 1.372522 0.728586 Swiss Franc 0.912533 1.095851 Malaysian Ringgit 4.179403 0.239269 Japanese Yen 105.972386 0.009436 Chinese Yuan Renminbi 6.916701 0.144578 Argentine Peso 73.579736 0.013591 Australian Dollar 1.397888 0.715365 Bahraini Dinar 0.376000 2.659574 Botswana Pula 11.637002 0.085933 Brazilian Real 5.612101 0.178186 British Pound 0.764894 1.307371 Bruneian Dollar 1.372522 0.728586 Bulgarian Lev 1.660274 0.602310 Canadian Dollar 1.319703 0.757746 Chilean Peso 788.670498 0.001268 Chinese Yuan Renminbi 6.916701 0.144578 Colombian Peso 3818.060261 0.000262 Croatian Kuna 6.387299 0.156561 Czech Koruna 22.154682 0.045137 Danish Krone 6.320690 0.158211 Emirati Dirham 3.672500 0.272294 Euro 0.848884 1.178017 Hong Kong Dollar 7.7...