Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Knapsack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python3

"""This program uses the greedy approach to solve the knapsack problem"""
import mysql.connector
import datetime
capacity=int(input("Enter the capacity of your knapsack:\n"))
Expand Down
10 changes: 5 additions & 5 deletions MergeSort.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import datetime
a = datetime.datetime.now()
def mergeSort(arr):
if len(arr) >1:
if (len(arr) >1):
mid = len(arr)//2
L = arr[:mid]
L = arr[0:mid]
R = arr[mid:]

mergeSort(L)
mergeSort(R)

i = j = k = 0

while i < len(L) and j < len(R):
while (i < len(L) and j < len(R)):
if L[i] < R[j]:
arr[k] = L[i]
i+=1
Expand All @@ -23,12 +23,12 @@ def mergeSort(arr):
k+=1


while i < len(L):
while (i < len(L)):
arr[k] = L[i]
i+=1
k+=1

while j < len(R):
while (j < len(R)):
arr[k] = R[j]
j+=1
k+=1
Expand Down