CP104 Lecture Notes - Lecture 13: Bubble Sort, Merge Sort, Insertion Sort

252 views3 pages
17 Jun 2017
School
Course
Professor
hayjayshay and 38575 others unlocked
CP104 Full Course Notes
2
CP104 Full Course Notes
Verified Note
2 documents

Document Summary

# imports import random from number import number from sorts_array import sorts import copy. Size = 100 # size of array to sort. Xrange = 1000 # range of values in random arrays to sort. Tests = 100 # number of random arrays to generate. Sorts = ( ("bubble sort", sorts. bubble_sort), ("insertion sort", sorts. insertion_sort), ("merge sort", sorts. merge_sort), ("quick sort", sorts. quick_sort), ("selection sort", sorts. selection_sort), ("bin. Sort", sorts. binary_insert_sort), ("cocktail sort", sorts. cocktail_sort), ("comb sort", sorts. comb_sort), ("heap sort", sorts. heap_sort), ("shell sort", sorts. shell_sort) def create_sorted(): Postconditions: returns values - a sorted list of size number objects. values = [] i = 0 while i < size: values. append(number(i)) i += 1 return values def create_reversed(): Postconditions: returns values - a reversed list of size number objects. values = [] i = 0 while i < size: values. append(number(i)) i += 1 values. reverse() return values def create_randoms(): Test a sort function with number data and print out its comparisons for sorted, reversed, and random arrays of data.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents