Ejemplo n.º 1
0
def test_with_list(test_data):
    print('MergeSort:')
    start_time = int(round(time.time() * 1000))
    result = MergeSort.merge_sort(test_data)
    duration = int(round(time.time() * 1000)) - start_time
    print('Duration: ' + str(duration) + 'ms')
    empty_target = result
    del result
    del start_time
    del duration

    print('InsertionSort:')
    start_time = int(round(time.time() * 1000))
    result = InsertionSort.insertion_sort(test_data)
    duration = int(round(time.time() * 1000)) - start_time
    print('Duration: ' + str(duration) + 'ms')
    empty_target = result
    del result
    del start_time
    del duration

    print('BubbleSort:')
    start_time = int(round(time.time() * 1000))
    result = BubbleSort.bubble_sort(test_data)
    duration = int(round(time.time() * 1000)) - start_time
    print('Duration: ' + str(duration) + 'ms')
    empty_target = result
    del result
    del start_time
    del duration

    print('SelectSort:')
    start_time = int(round(time.time() * 1000))
    result = SelectSort.select_sort(test_data)
    duration = int(round(time.time() * 1000)) - start_time
    print('Duration: ' + str(duration) + 'ms')
    empty_target = result
    del result
    del start_time
    del duration
Ejemplo n.º 2
0
import time
import random
import InsertionSort, MergeSort

if __name__ == "__main__":
    array_size = 10000
    arr = random.sample(range(1, 10001), array_size)
    arr_2 = list(arr)

    start_merge = time.time()
    MergeSort.merge_sort(arr)
    end_merge = time.time()

    start_insertion = time.time()
    InsertionSort.insertion_sort(arr_2)
    end_insertion = time.time()

    print("Merge sort :  %s seconds" % (end_merge - start_merge))
    print("Insertion sort :  %s seconds" % (end_insertion - start_insertion))
Ejemplo n.º 3
0
    ]  #<<<<<THIS IS TO TEST THE FINAL DISPLAY WITHOUT HAVING TO WAIT A LONG TIME
    results = [None] * 6
    time = timer.timer()

    #create the starting lists
    for x in range(0, 3):
        data[x] = rand.randomIntList(totals[x], 1, 999)

    #data set 1
    #bubble sort
    time.startTimer()
    r = bubble.bubble_sort(data[0])
    results[0] = time.endTimer()
    #merge Sort
    time.startTimer()
    r = merge.merge_sort(data[0])
    results[1] = time.endTimer()

    #data set 2
    #bubble sort
    time.startTimer()
    r = bubble.bubble_sort(data[1])
    results[2] = time.endTimer()
    #merge Sort
    time.startTimer()
    r = merge.merge_sort(data[1])
    results[3] = time.endTimer()

    #data set 3
    #bubble sort
    time.startTimer()
Ejemplo n.º 4
0
merge_times = []
insertion_times = []
WC_merge_times = []
WC_insertion_times = []

#Create 11 arrays of a random size from 1000 to 100000
for x in range(11):
    n.append(random.randrange(1000,100000,1))
    unsorted_arrays.append(make_array(n[x], 100))

sorted_arraysM = unsorted_arrays.copy()
#Sort all of the arrays using merge sort and save the time taken to sort
print("Merge Sort")
for x in range(11):
    startTime = time.time()
    MergeSort.merge_sort(sorted_arraysM[x])
    merge_times.append(time.time() - startTime)

sorted_arryasI = unsorted_arrays.copy()
#Sort all of the arrays using insertion sort and save the time taken to sort
print("Insertion Sort")
for x in range(11):
    startTime = time.time()
    InertionSort.insertion_sort(sorted_arryasI[x])
    insertion_times.append(time.time() - startTime)

#Store the array size and merge sort times in a pandas data frame
merge_df = pd.DataFrame(list(zip(n, merge_times)), columns = ['Size', 'Merge Sort Time'])
print(merge_df)

#Store the array size and insertion sort times in a pandas data frame
Ejemplo n.º 5
0
 def apply_sort(self, list_of_things):
     return MergeSort.merge_sort(list_of_things)
Ejemplo n.º 6
0
    QuickSort.quick_sort(test_list, 0, size - 1)
    finish = time.time()
    print("********************************")
    print("QuickSort: ", test_list)
    print("time: %f" % (finish - start))
    print("\n")

    test_list = [
        1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3, 45, 68, 125, 37,
        54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3,
        45, 68, 125, 37, 54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19,
        4234, 100, 2, 3, 45, 68, 125, 37, 54614, 2, 46, 67
    ]
    size = len(test_list)
    start = time.time()
    test_list = MergeSort.merge_sort(test_list)
    finish = time.time()
    print("********************************")
    print("MergeSort: ", test_list)
    print("time: %f" % (finish - start))
    print("\n")

    test_list = [
        1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3, 45, 68, 125, 37,
        54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19, 4234, 100, 2, 3,
        45, 68, 125, 37, 54614, 2, 46, 67, 1, 5, 52, 4, 23, 1, 32, 4, 5, 6, 19,
        4234, 100, 2, 3, 45, 68, 125, 37, 54614, 2, 46, 67
    ]
    size = len(test_list)
    start = time.time()
    HeapSort.heapsort(test_list)
Ejemplo n.º 7
0
import MergeSort
import NumList

# create a new NumList and print out contents

listSize = 10000

testList = NumList.NumList(listSize)

print "Pre MergeSort"
for x in testList.my_list:
    print "\t" + repr(x)

testList.my_list = MergeSort.merge_sort(testList.my_list)

print "Post MergeSort"
for x in testList.my_list:
    print "\t" + repr(x)

# pass to merge to sort and print out contents
Ejemplo n.º 8
0
    start_time = time.time()
    # Calling bubble_sort for each data set
    BubbleSort.bubble_sort(data["data" + str(i + 1)])
    print("Bubble time for data" + str(i + 1) + " = " +
          str(time.time() - start_time))

#-----------------------------------------------------------------------------#
#                  DECREASE AND CONQUER                                  #
#-----------------------------------------------------------------------------#

#                        INSERTION SORTING
for i in range(len(data)):
    # invoke the start time to measure the performance
    start_time = time.time()
    # Calling bubble_sort for each data set
    InsertionSort.insertion_sort_iterative(data["data" + str(i + 1)])
    print("Insertion time for data" + str(i + 1) + " = " +
          str(time.time() - start_time))

#-----------------------------------------------------------------------------#
#                        DIVIDE AND CONQ SORTING                         #
#-----------------------------------------------------------------------------#

#                        MERGE SORTING
for i in range(len(data)):
    # invoke the start time to measure the performance
    start_time = time.time()
    # Calling bubble_sort for each data set
    MergeSort.merge_sort(data["data" + str(i + 1)])
    print("Merge time for data" + str(i + 1) + " = " +
          str(time.time() - start_time))
Ejemplo n.º 9
0
# mergesort using just 1 core
import MergeSort  # Imports mergesort functions
import random
import time

# Create an array to be sorted
arraylength = 1000000  # Length of array to be sorted
print('Length of array is', arraylength)
array = list(range(arraylength))  # Creates array
random.shuffle(array)  # Jumbles up array

# Sort and time sorting process
start_time = time.time()  # Records start time
print('Sorting array...')
array = MergeSort.merge_sort(array)  # Sorts array
print('Array sorted.')
time_taken = time.time() - start_time  # Calculates and records time_taken

print('Time taken to sort is ', time_taken, 'seconds.')