Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- CHAPTER 1
- '''
- def selectionSort(A):
- n = len(A)
- for j in range(0, n-1):
- for i in range(j+1, n):
- if A[j] > A[i]:
- A[j], A[i] = A[i], A[j]
- return A
- # MAIN FUNCTION - 1
- myList = [2, 4, 5, 1, 6, 3]
- print("Initial list: " + str(myList))
- print("Sorted list with my method: " + str(selectionSort(myList)))
- print("Sorted list with Python's default method: " + str(sorted(myList)))
- print()
- '''
- CHAPTER 2
- '''
- import random
- # Create a list of 3000 integers in range 1 .... 1000
- newList = [random.randint(1, 1000) for i in range(3000)]
- from timeit import default_timer as timer
- executions = list(range(100, 3100, 100))
- measurements = []
- # executions = [100, 200, 300, ...., 2900, 3000]
- print()
- print("~~~~ This process will take less than 10 seconds. Just wait ~~~~")
- print()
- print()
- for num in executions:
- start = timer()
- selectionSort(newList[0: num])
- end = timer()
- measurements.append(end - start)
- print("Elements Execution Time")
- for i in range(len(executions)):
- print(str(executions[i]) + " " + str(measurements[i] * 1000) + "ms")
- '''
- CHAPTER 3
- '''
- # Plots time
- import matplotlib.pyplot as plt
- plt.plot(executions, measurements)
- plt.xlabel("Number of Elements")
- plt.ylabel("Execution Time")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement