def calcularTiempoAlgoritmos(arreglo, tamanio,archivo):
    tiempos=[]
    #Tiempo RadixSort
    arreglo = generarArreglo(arreglo,tamanio)
    inicio = time()
    ordenadoRadix = radixSort(arreglo.copy(), 10)
    final = time()
    tiempos.append(final-inicio)

    #Tiempo QuickSort
    aux = arreglo.copy()
    inicio = time()
    quickSort(aux)
    final = time()
    tiempos.append(final-inicio)


    # Tiempo bubbleSort
    aux2 = arreglo.copy()
    inicio = time()
    bubbleSort(aux2)
    final = time()
    tiempos.append(final-inicio)


    #Tiempo shellSort
    aux3 = arreglo.copy()
    inicio = time()
    shellSort(aux3)
    final = time()
    tiempos.append(final-inicio)
    

    #Tiempo heapsort
    aux4 = arreglo.copy()
    inicio = time()
    heapsort(aux4)
    final = time()
    tiempos.append(final-inicio)
    
    
    archivo.write(str(tamanio))
    for element in tiempos:
        linea+=","+str(element*1000) #para que quede en milisegundos
    archivo.write("\n")
Ejemplo n.º 2
0
def save_time(i, list):
    start = time.clock()
    time_bubble[i] = bubblesort(list[0])		# Tempo do bubblesort
    time_quick[i] = quicksort(list[1])		# Tempo do quicksort
    time_insert[i] = insertionsort(list[2])  # Tempo do insertionsort
    time_shell[i] = shellsort(list[3])		# Tempo do shellsort
    time_select[i] = selectionsort(list[4])  # Tempo do selectionsort
    time_heap[i] = heapsort(list[5])		# Tempo do heapsort
    time_merge[i] = mergesort(list[6])		# Tempo do merge
    end = time.clock()
    actualtime = end - start
    print "Tamanho de lista: {0} | Tempo para a execucao de todos algoritmos: {1}s".format(len(list[0]), actualtime)
    return  # forca a saida
Ejemplo n.º 3
0
##Test Merge Sort
start = current_time()
merge_sort(data1, 0, len(data1) - 1)
end = current_time()
print("Merge Sort time : %d mil.seconds" % (end - start))

##Test Insertion Sort
start = current_time()
insertion_sort(data10)
end = current_time()
print("Insertion Sort time : %d mil.seconds" % (end - start))

##Test Heap Sort
start = current_time()
heapsort(data3)
end = current_time()
print("Heap Sort time : %d mil.seconds" % (end - start))

##Test Counting Sort
start = current_time()
counting_sort(data4, data5, max(data4))
end = current_time()
print("Counting Sort time : %d mil.seconds" % (end - start))

##Test Radix Sort
start = current_time()
radixsort(data6)
end = current_time()
print("Radix Sort time : %d mil.seconds" % (end - start))
Ejemplo n.º 4
0
import numpy as np
import argparse

from heapsort import *

parser = argparse.ArgumentParser()
parser.add_argument("arq_vetor",
                    help="nome do arquivo contendo o vetor de teste")
args = parser.parse_args()

# Lê o arquivo contendo o vetor e passado na linha de comando como um
# vetor do Numpy.

vet = np.loadtxt(args.arq_vetor)
heapsort(vet)
Ejemplo n.º 5
0
from heapsort import *

A = [4, 1, 3, 2, 16, 9, 10, 14, 8, 7]
print("Original: ", A)

buildMaxHeap(A)
print("Heapified: ", A)

sortedList = heapsort(A)
print("Sorted: ", sortedList)


Ejemplo n.º 6
0
#!/usr/bin/env python

import sys
import random
from timeit import timeit

from bubblesort    import bubblesort
from mergesort     import mergesort
from quicksort     import quicksort
from insertionsort import insertionsort
from gnomesort     import gnomesort
from selectionsort import selectionsort
from heapsort      import *

#elements = sys.argv[1:]
## we need ints, not strings
#elements = list(map(int, elements))

elements = [ random.randint(1,20) for _ in range(20) ]

print(elements)
print(bubblesort(elements[:]))
print(mergesort(elements[:]))
print(quicksort(elements[:]))
print(insertionsort(elements[:]))
print(gnomesort(elements[:]))
print(selectionsort(elements[:]))
print(heapsort(elements[:]))