Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from timeit import timeit
- from random import randint
- def geraLista(tam):
- lista = []
- for i in range(tam):
- n = randint(1,1*tam)
- if n not in lista: lista.append(n)
- return lista
- def bubbleSort(lista):
- for i in range(0,len(lista)):
- for j in range(i+1,len(lista)):
- if lista[i] > lista[j]:
- auxi = lista[i]
- lista[i] = lista[j]
- lista[j] = auxi
- ordenada = lista
- return ordenada
- tams = []
- tempos = []
- for tam in range(3000,24001,3000):
- lista = geraLista(tam)
- tempo = timeit("bubbleSort({})".format(lista),setup="from __main__ import bubbleSort",number=1)
- tams.append(tam)
- tempos.append(tempo)
- import matplotlib as plt
- plt.use('Agg')
- import matplotlib.pyplot as plt
- def desenhaGrafico(x,y,xl = "Entradas", yl = "Saídas"):
- fig = plt.figure(figsize=(10, 8))
- ax = fig.add_subplot(111)
- ax.plot(x,y, label = "Melhor Tempo")
- ax.legend(bbox_to_anchor=(1, 1),bbox_transform=plt.gcf().transFigure)
- plt.ylabel(yl)
- plt.xlabel(xl)
- fig.savefig('graph.png')
- desenhaGrafico(tams, tempos, "Tamanhos(n)", "Tempo(s)")
Add Comment
Please, Sign In to add comment