def Start_alg(): global data, size, crono if alg_menu.get() == "Bubble Sort": # if buble sort selected: start = time.perf_counter() # start a timer bubble_sort(data, drawdata, 0) # call the sort function end = time.perf_counter() # stop the timer when the function ends timetext = str(f'Bubble {size} en {round(end - start, 2)} \n') # write the timing in the program crono.insert(0.0, str(timetext)) dbb_alg = "Bubble" # create variables to insert them in the SQL table dbb_size = size dbb_sec = round(end - start, 2) sqlformula = "INSERT INTO sortdata (alg, size, sec) VALUES (%s, %s, %s)" dades = (dbb_alg, dbb_size, dbb_sec) # insert the data elif alg_menu.get() == "Selection Sort": start = time.perf_counter() selection(data, drawdata, 0) end = time.perf_counter() drawdata(data, ['green' for x in range(len(data))]) timetext = str(f'Selection {size} en {round(end - start, 2)} \n') crono.insert(0.0, str(timetext)) dbm_alg = "selection" dbm_size = size dbm_sec = round(end - start, 2) sqlformula = "INSERT INTO sortdata (alg, size, sec) VALUES (%s, %s, %s)" dades = (dbm_alg, dbm_size, dbm_sec)
def startAlgorithm(): global data if not data: return if algMenu.get() == 'Quick Sort': quick_sort(data, 0, len(data) - 1, drawData, speedScale.get()) elif algMenu.get() == 'Bubble Sort': bubble_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Insertion Sort': insertion_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Merge Sort': merge_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Selection Sort': selection_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Selection Sort': selection_sort(data, drawData, speedScale.get()) elif algMenu.get() == 'Radix Sort': radix_sort(data, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))])
def StartAlgorithm(): global data if not data: return if algMenu.get() == 'Quick Sort': quick_sort(data, 0, len(data) - 1, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))]) elif algMenu.get() == 'Bubble Sort': bubble_sort(data, drawData, speedScale.get())
def satrtAlgo(): global data if not data: return if (algMenu.get() == 'Quick Sort'): quick_sort(data, 0, len(data) - 1, drawData, speedScale.get()) elif (algMenu.get() == 'Bubble Sort'): bubble_sort(data, drawData, speedScale.get()) elif (algMenu.get() == 'Merge Sort'): merge_sort(data, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))])
def StartAlgorithm(): #print("Starting Algorithm .....") global data if not data: return if (algoMenu.get() == "Quick Sort"): quick_sort(data, 0, len(data)-1, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))]) elif (algoMenu.get() == 'Bubble Sort'): bubble_sort(data, drawData, speedScale.get())
def startAlgorith(): global data #Calling the necessary algorith if alg_menu.get() == 'BubbleSort': bubble_sort(data, drawData, speedScale.get()) elif alg_menu.get() == 'InsertionSort': insertion_sort(data, drawData, speedScale.get()) elif alg_menu.get() == 'MergeSort': merge_sort(data, drawData, speedScale.get())
def startAlgo(): global data if not data: return if algMenu.get() == 'Quick Sort': quick_sort(data, 0, len(data) - 1, drawData, speedScale.get(), sizeEntry.get()) elif algMenu.get() == 'Bubble Sort': bubble_sort(data, drawData, speedScale.get(), sizeEntry.get()) elif algMenu.get() == 'Merge Sort': start_mergeSort(data, drawData, speedScale.get(), sizeEntry.get()) drawData(data, sizeEntry.get(), ['navy' for x in range(len(data))])
def startAlgorithm(): global array if not array: return # get the speed of the algorithm visualiser sizeNum = sizeEntry.get() speed = 10 / (sizeNum * pow(sizeNum, 0.5)) # visualise an algorithm if algoMenu.get() == "Insertionsort": insertion_sort(array, drawArray, speed) if algoMenu.get() == "Mergesort": merge_sort(array, drawArray, speed) if algoMenu.get() == "Bubblesort": bubble_sort(array, drawArray, speed) if algoMenu.get() == "Quicksort": quick_sort(array, drawArray, speed) if algoMenu.get() == "Heapsort": heap_sort(array, drawArray, speed)
def StartAlgorithm(): global data start = time.time() data2 = copy.deepcopy(data) if (selected_alg.get() == 'Quick Sort'): quickSort(data, 0, len(data) - 1, drawData, speedScale.get()) if (selected_alg.get() == 'Bubble Sort'): bubble_sort(data, drawData, speedScale.get()) if (selected_alg.get() == 'Merge Sort'): merge_sort(data, drawData, speedScale.get()) drawData(data, ['green' for x in range(len(data))]) data = data2 messagebox.showinfo( "Data Sorted!: ", f"Sorting algorithm used: {selected_alg.get()} \nSpeed Scale: {speedScale.get()} \nTotal time taken: {time.time()-start} " )
def start_algo(): global data if not data: return if algoMenu.get() == 'Quick Sort': quick_sort(data, 0, len(data) - 1, draw_Data, speedScale.get()) elif algoMenu.get() == 'Bubble sort': bubble_sort(data, draw_Data, speedScale.get()) elif algoMenu.get() == 'Merge Sort': merge_sort(data, draw_Data, speedScale.get()) elif algoMenu.get() == 'Insertion Sort': insertion_sort(data, draw_Data, speedScale.get()) elif algoMenu.get() == 'Heap Sort': heap_sort(data, draw_Data, speedScale.get()) draw_Data(data, ['green' for x in range(len(data))])
def main(): parser = argparse.ArgumentParser() parser.add_argument('--n', type=int, default=8) args = parser.parse_args() total_number = args.n input_list = np.random.randint(10, total_number*10, total_number) bubbleSort.bubble_sort(input_list) print(input_list) print('What are you looking for?') target = int(input('>> ')) index = binary_search(input_list, target, 0, total_number) if index < 0: print('{0} is not found in the tuple'.format(target)) else: print(index+1)
def startAlgorithm_1(): global data bubble_sort(data, bar)
def main(): target = 5 unsortedList = [64,6,10,84,4163,5454,1,2,4,4584,5,42,18] sortedList = bubble_sort(unsortedList) print("Using :", sortedList) binary_search(sortedList, target)
def StartAlgorithm(): global data bubble_sort(data, drawData, speedScale.get())
from selectionSort import selection_sort from insertionSort import insertion_sort from bubbleSort import bubble_sort from binarySearch import binary_search import random random_array = [random.randint(1, 100) for _ in range(100)] print("Selection sort time:") selection_sort(random_array) print(binary_search(random_array, 76)) print("Insertion sort time:") insertion_sort(random_array) print("Bubble sort time:") bubble_sort(random_array)
def start_sort(): global data bubble_sort(data, draw_data)
def main(): from quickSort import q_count sys.setrecursionlimit(10000) # instantiate write to file write_file = WriteToFile() merge_sort = MergeSort() # 100 list first_list, second_list, third_list, fourth_list = arrayGenerator.generate_random_list_number(100) print("{}, {}, {}, {}".format(len(first_list), len(second_list), len(third_list), len(fourth_list))) # sorting 100 list with bubblesort start_time = time.perf_counter() first_list, comparisons = bubbleSort.bubble_sort(first_list) end_time = time.perf_counter() print("Bubble Sort time: %s seconds" % (end_time - start_time)) print("Bubble Sort comparisions: ", comparisons) # Creating the semisorted list first_list = arrayGenerator.randomizer(first_list) # sorting 100 semisorted list with bubblesort start_time_semisorted = time.perf_counter() first_list, semisorted_comparisons = bubbleSort.bubble_sort(first_list) end_time_semisorted = time.perf_counter() print("Bubble Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Bubble Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Bubble Sort data to the file write_file.write_to_file('Bubble Sort', 'O(n^2)', 'O(n)', 100, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 100 list with selectionsort start_time = time.perf_counter() second_list, comparisons = selectionSort.selection_sort(second_list) end_time = time.perf_counter() print("Selection Sort time: %s seconds" % (end_time - start_time)) print("Selection Sort comparisions: ", comparisons) # Creating the semisorted list second_list = arrayGenerator.randomizer(second_list) # sorting 100 semisorted list with selectionsort start_time_semisorted = time.perf_counter() second_list, semisorted_comparisons = selectionSort.selection_sort(first_list) end_time_semisorted = time.perf_counter() print("Selection Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Selection Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Selection Sort data to the file write_file.write_to_file('Selection Sort', 'O(n^2)', 'O(n^2)', 100, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 100 list with mergesort start_time = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time = time.perf_counter() print("Merge Sort time: %s seconds" % (end_time - start_time)) comparisons = merge_sort.count print("Merge Sort comparisions: ", merge_sort.count) # Creating the semisorted list third_list = arrayGenerator.randomizer(third_list) # sorting 100 semisorted list with mergesort start_time_semisorted = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time_semisorted = time.perf_counter() print("Merge Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = merge_sort.count print("Merge Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Merge Sort data to the file write_file.write_to_file('Merge Sort', 'O(nlog(n))', 'O(nlog(n))', 100, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 100 list with quicksort start_time = time.perf_counter() quickSort.quick_sort(fourth_list) end_time = time.perf_counter() print("Quick Sort time: %s seconds " % (end_time - start_time)) comparisons = quickSort.q_count print("Quick Sort comparisions: ", quickSort.q_count) # Creating the semisorted list fourth_list = arrayGenerator.randomizer(fourth_list) # sorting 100 semisorted list with quicksort start_time_semisorted = time.perf_counter() quickSort.quick_sort(fourth_list) end_time_semisorted = time.perf_counter() print("Quick Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = quickSort.q_count print("Quick Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Quick Sort data to the file write_file.write_to_file('Quick Sort', 'O(n^2)', 'O(nlog(n))', 100, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # 1000 list first_list, second_list, third_list, fourth_list = arrayGenerator.generate_random_list_number(1000) print("{}, {}, {}, {}".format(len(first_list), len(second_list), len(third_list), len(fourth_list))) # sorting 1000 list with bubblesort start_time = time.perf_counter() first_list, comparisons = bubbleSort.bubble_sort(first_list) end_time = time.perf_counter() print("Bubble Sort time: %s seconds" % (end_time - start_time)) print("Bubble Sort comparisions: ", comparisons) # Creating the semisorted list first_list = arrayGenerator.randomizer(first_list) # sorting 1000 semisorted list with bubblesort start_time_semisorted = time.perf_counter() first_list, semisorted_comparisons = bubbleSort.bubble_sort(first_list) end_time_semisorted = time.perf_counter() print("Bubble Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Bubble Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Bubble Sort data to the file write_file.write_to_file('Bubble Sort', 'O(n^2)', 'O(n)', 1000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 1000 list with selectionsort start_time = time.perf_counter() second_list, comparisons = selectionSort.selection_sort(second_list) end_time = time.perf_counter() print("Selection Sort time: %s seconds" % (end_time - start_time)) print("Selection Sort comparisions: ", comparisons) # Creating the semisorted list second_list = arrayGenerator.randomizer(second_list) # sorting 1000 semisorted list with selectionsort start_time_semisorted = time.perf_counter() second_list, semisorted_comparisons = selectionSort.selection_sort(first_list) end_time_semisorted = time.perf_counter() print("Selection Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Selection Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Selection Sort data to the file write_file.write_to_file('Selection Sort', 'O(n^2)', 'O(n^2)', 1000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 1000 list with mergesort start_time = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time = time.perf_counter() print("Merge Sort time: %s seconds" % (end_time - start_time)) print("Merge Sort comparisions: ", merge_sort.count) # Creating the semisorted list third_list = arrayGenerator.randomizer(third_list) # sorting 1000 semisorted list with mergesort start_time_semisorted = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time_semisorted = time.perf_counter() print("Merge Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = merge_sort.count print("Merge Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Merge Sort data to the file write_file.write_to_file('Merge Sort', 'O(nlog(n))', 'O(nlog(n))', 1000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 1000 list with quicksort start_time = time.perf_counter() quickSort.quick_sort(fourth_list) end_time = time.perf_counter() print("Quick Sort time: %s seconds " % (end_time - start_time)) comparisons = quickSort.q_count print("Quick Sort comparisions: ", quickSort.q_count) # Creating the semisorted list fourth_list = arrayGenerator.randomizer(fourth_list) # sorting 1000 semisorted list with quicksort start_time_semisorted = time.perf_counter() quickSort.quick_sort(fourth_list) end_time_semisorted = time.perf_counter() print("Quick Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = quickSort.q_count print("Quick Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Quick Sort data to the file write_file.write_to_file('Quick Sort', 'O(n^2)', 'O(nlog(n))', 1000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # 10000 list first_list, second_list, third_list, fourth_list = arrayGenerator.generate_random_list_number(10000) print("{}, {}, {}, {}".format(len(first_list), len(second_list), len(third_list), len(fourth_list))) # sorting 10000 list with bubblesort start_time = time.perf_counter() first_list, comparisons = bubbleSort.bubble_sort(first_list) end_time = time.perf_counter() print("Bubble Sort time: %s seconds" % (end_time - start_time)) print("Bubble Sort comparisions: ", comparisons) # Creating the semisorted list first_list = arrayGenerator.randomizer(first_list) # sorting 10000 semisorted list with bubblesort start_time_semisorted = time.perf_counter() first_list, semisorted_comparisons = bubbleSort.bubble_sort(first_list) end_time_semisorted = time.perf_counter() print("Bubble Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Bubble Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Bubble Sort data to the file write_file.write_to_file('Bubble Sort', 'O(n^2)', 'O(n)', 10000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 10000 list with selectionsort start_time = time.perf_counter() second_list, comparisons = selectionSort.selection_sort(second_list) end_time = time.perf_counter() print("Selection Sort time: %s seconds" % (end_time - start_time)) print("Selection Sort comparisions: ", comparisons) # Creating the semisorted list second_list = arrayGenerator.randomizer(second_list) # sorting 10000 semisorted list with selectionsort start_time_semisorted = time.perf_counter() second_list, semisorted_comparisons = selectionSort.selection_sort(first_list) end_time_semisorted = time.perf_counter() print("Selection Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) print("Selection Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Selection Sort data to the file write_file.write_to_file('Selection Sort', 'O(n^2)', 'O(n^2)', 10000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 10000 list with mergesort start_time = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time = time.perf_counter() print("Merge Sort time: %s seconds" % (end_time - start_time)) print("Merge Sort comparisions: ", merge_sort.count) # Creating the semisorted list third_list = arrayGenerator.randomizer(third_list) # sorting 10000 semisorted list with mergesort start_time_semisorted = time.perf_counter() third_list = merge_sort.merge_sort(third_list) end_time_semisorted = time.perf_counter() print("Merge Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = merge_sort.count print("Merge Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Merge Sort data to the file write_file.write_to_file('Merge Sort', 'O(nlog(n))', 'O(nlog(n))', 10000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) # sorting 10000 list with quicksort start_time = time.perf_counter() quickSort.quick_sort(fourth_list) end_time = time.perf_counter() print("Quick Sort time: %s seconds " % (end_time - start_time)) comparisons = quickSort.q_count print("Quick Sort comparisions: ", quickSort.q_count) # Creating the semisorted list fourth_list = arrayGenerator.randomizer(fourth_list) # sorting 10000 semisorted list with quicksort start_time_semisorted = time.perf_counter() quickSort.quick_sort(fourth_list) end_time_semisorted = time.perf_counter() print("Quick Sort time on semisorted array: %s seconds" % (end_time_semisorted - start_time_semisorted)) semisorted_comparisons = quickSort.q_count print("Quick Sort comparisions on semisorted array: ", semisorted_comparisons) # Writing the Quick Sort data to the file write_file.write_to_file('Quick Sort', 'O(n^2)', 'O(nlog(n))', 10000, end_time - start_time, comparisons, end_time_semisorted - start_time_semisorted, semisorted_comparisons) write_file.close()
quickSort.quick_sort(data5,0,len(data5)) e5 = time.clock() print 'quick_sort:', e5-s5 s6 = time.clock() quickSort.qSort(data6) e6 = time.clock() print 'qSort:', e6-s6 s3 = time.clock() insertionSort.insertionSort(data3) e3 = time.clock() print 'insertionSort:', e3-s3 s8 = time.clock() insertionSort.insertSort(data8, 0, len(data8)) e8 = time.clock() print 'insertSort:', e8-s8 s4 = time.clock() selectionSort.selectionSort(data4) e4 = time.clock() print 'selectionSort:', e4-s4 s2 = time.clock() bubbleSort.bubble_sort(data2, 0, len(data2)) e2 = time.clock() print 'bubble_sort:', e2-s2
from quickSort import quick_sort from selectionSort import selection_sort from shellSort import shell_sort from random import randint how_many = 1000 lower_integer = 0 upper_integer = 999 if __name__ == "__main__": array = [] for i in range(how_many): array.append(randint(lower_integer, upper_integer)) temp = array[:] bubble_sort(temp) temp = array[:] bucket_sort(temp, how_many // 100) temp = array[:] comb_sort(temp) temp = array[:] counting_sort(temp) temp = array[:] heap_sort(temp) temp = array[:] insertion_sort(temp) temp = array[:] shell_sort(temp) temp = array[:] lsd_radix_sort(temp) temp = array[:]