diff --git a/BinarySearch.py b/BinarySearch.py index d237395..738663a 100644 --- a/BinarySearch.py +++ b/BinarySearch.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 import mysql.connector - - +import datetime +a=datetime.datetime.now() def binsearch(array, first, last, element): if(last >= first): mid = (first+last)//2 @@ -32,3 +32,6 @@ def binsearch(array, first, last, element): print("The Roll No is found at the position: " + str(result+1) + " in the Database") else: print("Sorry the Roll No " + str(element) + " is not found in the Database! ") +b=datetime.datetime.now() +c=b-a +print("The time taken to search a rollno. using binary search= ",c) diff --git a/Knapsack.py b/Knapsack.py index 9a84edc..770e7ef 100644 --- a/Knapsack.py +++ b/Knapsack.py @@ -1,4 +1,9 @@ +#The knapsack problem is: Given a set of items, each with a weight and a value, +#determine the number of each item to include in a collection +#the total weight is less than or equal to a given limit and the total value is as large as possible. + #!/usr/bin/python3 + import mysql.connector import datetime capacity=int(input("Enter the capacity of your knapsack:\n"))