Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- import matplotlib.pyplot as plt
- print("EWWWW")
- f = open("input.txt", "r")
- input = []
- for k in f.readlines():
- input.append(int(k[:-2]))
- print("Length of input ", len(input))
- n = 500
- x_axis = []
- y_axis = []
- while n <=10000:
- total_time = 0
- for i in range(3):
- input2 = input[:n].copy()
- t1 = datetime.now()
- ########################### Buble sortuuuuu
- swapped = False
- for i in range(n-1):
- for j in range(0, n-i-1):
- if input2[j] > input2[j + 1]:
- swapped = True
- input2[j], input2[j + 1] = input2[j + 1], input2[j]
- if not swapped:
- break
- ###########################
- t2 = datetime.now()
- time_diff = t2-t1
- time_diff = time_diff.total_seconds()
- total_time += time_diff
- print(time_diff, end=' ')
- avg_time = total_time/3
- print(avg_time)
- x_axis.append(n)
- y_axis.append(avg_time)
- n = n + 500
- plt.plot(x_axis, y_axis)
- plt.xticks([500*r for r in range(21)])
- plt.yticks([0.5*r for r in range(16)])
- plt.xlabel('Number of Inputs')
- plt.ylabel('Avg Time Taken in secs')
- plt.title('Bubble sort time')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment