Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- import timeit
- from heapq import merge
- import random
- from functools import total_ordering
- from bisect import bisect_left
- from math import log
- """ RADIX SORT"""
- def getDigit(num, base, digit_num):
- # pulls the selected digit
- return (num // base ** digit_num) % base
- def makeBlanks(size):
- # create a list of empty lists to hold the split by digit
- return [ [] for i in range(size) ]
- def split(a_list, base, digit_num):
- buckets = makeBlanks(base)
- for num in a_list:
- # append the number to the list selected by the digit
- buckets[getDigit(num, base, digit_num)].append(num)
- return buckets
- # concatenate the lists back in order for the next step
- def rmerge(a_list):
- new_list = []
- for sublist in a_list:
- new_list.extend(sublist)
- return new_list
- def maxAbs(a_list):
- # largest abs value element of a list
- return max(abs(num) for num in a_list)
- def split_by_sign(a_list):
- # splits values by sign - negative values go to the first bucket,
- # non-negative ones into the second
- buckets = [[], []]
- for num in a_list:
- if num < 0:
- buckets[0].append(num)
- else:
- buckets[1].append(num)
- return buckets
- def radix_sort(a_list, base):
- # there are as many passes as there are digits in the longest number
- passes = int(round(log(maxAbs(a_list), base)) + 1)
- new_list = list(a_list)
- for digit_num in range(passes):
- new_list = rmerge(split(new_list, base, digit_num))
- return rmerge(split_by_sign(new_list))
- """ PATIENCE SORT """
- @total_ordering
- class Pile(list):
- def __lt__(self, other): return self[-1] < other[-1]
- def __eq__(self, other): return self[-1] == other[-1]
- def patience_sort(n):
- piles = []
- # sort into piles
- for x in n:
- new_pile = Pile([x])
- i = bisect_left(piles, new_pile)
- if i != len(piles):
- piles[i].append(x)
- else:
- piles.append(new_pile)
- # use a heap-based merge to merge piles efficiently
- n[:] = merge(*[reversed(pile) for pile in piles])
- return n
- """ MERGE SORT """
- def merge_sort(m):
- if len(m) <= 1:
- return m
- middle = len(m) // 2
- left = m[:middle]
- right = m[middle:]
- left = merge_sort(left)
- right = merge_sort(right)
- return list(merge(left, right))
- """ HEAP SORT """
- def heap_sort(lst):
- ''' Heapsort. Note: this function sorts in-place (it mutates the list). '''
- # in pseudo-code, heapify only called once, so inline it here
- for start in range((len(lst)-2)/2, -1, -1):
- siftdown(lst, start, len(lst)-1)
- for end in range(len(lst)-1, 0, -1):
- lst[end], lst[0] = lst[0], lst[end]
- siftdown(lst, 0, end - 1)
- return lst
- def siftdown(lst, start, end):
- root = start
- while True:
- child = root * 2 + 1
- if child > end: break
- if child + 1 <= end and lst[child] < lst[child + 1]:
- child += 1
- if lst[root] < lst[child]:
- lst[root], lst[child] = lst[child], lst[root]
- root = child
- else:
- break
- """ QUICK SORT """
- def quick_sort(arr):
- less = []
- pivotList = []
- more = []
- if len(arr) <= 1:
- return arr
- else:
- pivot = arr[0]
- for i in arr:
- if i < pivot:
- less.append(i)
- elif i > pivot:
- more.append(i)
- else:
- pivotList.append(i)
- less = quick_sort(less)
- more = quick_sort(more)
- return less + pivotList + more
- """ SIMPLE SORT """
- def simple_sort(unsorted_set, order):
- sorted_list = []
- for i in order:
- if i in unsorted_set:
- sorted_list.append(i)
- return sorted_list
- """ SHELL SORT """
- def shell_sort(seq):
- inc = len(seq) // 2
- while inc:
- for i, el in enumerate(seq):
- while i >= inc and seq[i - inc] > el:
- seq[i] = seq[i - inc]
- i -= inc
- seq[i] = el
- inc = 1 if inc == 2 else int(inc * 5.0 / 11)
- return seq
- """ BUBBLE SORT """
- def bubble_sort(seq):
- """Inefficiently sort the mutable sequence (list) in place.
- seq MUST BE A MUTABLE SEQUENCE.
- As with list.sort() and random.shuffle this does NOT return
- """
- changed = True
- while changed:
- changed = False
- for i in xrange(len(seq) - 1):
- if seq[i] > seq[i+1]:
- seq[i], seq[i+1] = seq[i+1], seq[i]
- changed = True
- return seq
- """ INSERTION SORT """
- def insertion_sort(l):
- for i in xrange(1, len(l)):
- j = i-1
- key = l[i]
- while (l[j] > key) and (j >= 0):
- l[j+1] = l[j]
- j -= 1
- l[j+1] = key
- return l
- """ INSERTION SORT BINARY """
- def insertion_sort_bin(seq):
- for i in range(1, len(seq)):
- key = seq[i]
- # invariant: ``seq[:i]`` is sorted
- # find the least `low' such that ``seq[low]`` is not less then `key'.
- # Binary search in sorted sequence ``seq[low:up]``:
- low, up = 0, i
- while up > low:
- middle = (low + up) // 2
- if seq[middle] < key:
- low = middle + 1
- else:
- up = middle
- # insert key at position ``low``
- seq[:] = seq[:low] + [key] + seq[low:i] + seq[i + 1:]
- return seq
- """ CIRCLE SORT """
- def circle_sort_backend(A=[], L=0, R=0):
- '''
- >>> L = [3, 2, 8, 28, 2,]
- >>> circle_sort(L)
- 3
- >>> print(L)
- [2, 2, 3, 8, 28]
- >>> L = [3, 2, 8, 28,]
- >>> circle_sort(L)
- 1
- >>> print(L)
- [2, 3, 8, 28]
- '''
- n = R-L
- if n < 2:
- return 0
- swaps = 0
- m = n//2
- for i in range(m):
- if A[R-(i+1)] < A[L+i]:
- (A[R-(i+1)], A[L+i],) = (A[L+i], A[R-(i+1)],)
- swaps += 1
- if (n & 1) and (A[L+m] < A[L+m-1]):
- (A[L+m-1], A[L+m],) = (A[L+m], A[L+m-1],)
- swaps += 1
- return swaps + circle_sort_backend(A, L, L+m) + circle_sort_backend(A, L+m, R)
- def circle_sort(L=[]):
- swaps = 0
- s = 1
- while s:
- s = circle_sort_backend(L, 0, len(L))
- swaps += s
- return L
- """ COCKTAIL SORT """
- def cocktail_sort(A):
- up = range(len(A)-1)
- while True:
- for indices in (up, reversed(up)):
- swapped = False
- for i in indices:
- if A[i] > A[i+1]:
- A[i], A[i+1] = A[i+1], A[i]
- swapped = True
- if not swapped:
- return A
- """ COUNTING SORT """
- def counting_sort(array, mn, mx):
- count = defaultdict(int)
- for i in array:
- count[i] += 1
- result = []
- for j in range(mn,mx+1):
- result += [j]* count[j]
- return result
- """ CYCLE SORT """
- def cycle_sort(vector):
- "Sort a vector in place and return the number of writes."
- writes = 0
- # Loop through the vector to find cycles to rotate.
- for cycleStart, item in enumerate(vector):
- # Find where to put the item.
- pos = cycleStart
- for item2 in vector[cycleStart + 1:]:
- if item2 < item:
- pos += 1
- # If the item is already there, this is not a cycle.
- if pos == cycleStart:
- continue
- # Otherwise, put the item there or right after any duplicates.
- while item == vector[pos]:
- pos += 1
- vector[pos], item = item, vector[pos]
- writes += 1
- # Rotate the rest of the cycle.
- while pos != cycleStart:
- # Find where to put the item.
- pos = cycleStart
- for item2 in vector[cycleStart + 1:]:
- if item2 < item:
- pos += 1
- # Put the item there or right after any duplicates.
- while item == vector[pos]:
- pos += 1
- vector[pos], item = item, vector[pos]
- writes += 1
- return vector
- """ GNOME SORT """
- def gnome_sort(a):
- i,j,size = 1,2,len(a)
- while i < size:
- if a[i-1] <= a[i]:
- i,j = j, j+1
- else:
- a[i-1],a[i] = a[i],a[i-1]
- i -= 1
- if i == 0:
- i,j = j, j+1
- return a
- """ PANCAKE SORT """
- def pancake_sort(data):
- if len(data) <= 1:
- return data
- for size in range(len(data), 1, -1):
- maxindex = max(range(size), key=data.__getitem__)
- if maxindex+1 != size:
- # This indexed max needs moving
- if maxindex != 0:
- # Flip the max item to the left
- data[:maxindex+1] = reversed(data[:maxindex+1])
- # Flip it into its final position
- data[:size] = reversed(data[:size])
- return data
- """ SELECTION SORT """
- def selection_sort(lst):
- for i, e in enumerate(lst):
- mn = min(range(i,len(lst)), key=lst.__getitem__)
- lst[i], lst[mn] = lst[mn], e
- return lst
- """
- Binary Search Tree: A sorted collection of values that supports
- efficient insertion, deletion, and minimum/maximum value finding.
- """
- # Copyright (C) 2008 by Edward Loper
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- # IMPLEMENTATION NOTES:
- #
- # Internally, we represent tree nodes using Python lists. These lists
- # may either be empty (for empty nodes) or may have length four (for
- # non-empty nodes). The non-empty nodes contain:
- #
- # [left_child, right_child, value, sort_key]
- #
- # Using lists rather than a node class more than doubles the overall
- # performance in the benchmarks that I have run.
- #
- # The sort key is always accessed as node[-1]. This allows us to
- # optimize the case where the sort key is identical to the value, by
- # encoding such nodes as simply:
- #
- # [left_child, right_child, value]
- #
- # The following constants are used to access the pieces of each search
- # node. If the constant-binding optimization recipe (which can be
- # downloaded from <http://code.activestate.com/recipes/277940/>) is
- # available, then it is used to replace these constants at
- # import-time, increasing the binary search tree efficiency by 3-5%.
- _LEFT = 0
- _RIGHT = 1
- _VALUE = 2
- _SORT_KEY = -1
- class BinarySearchTree(object):
- """
- A sorted collection of values that supports efficient insertion,
- deletion, and minimum/maximum value finding. Values may sorted
- either based on their own value, or based on a key value whose
- value is computed by a key function (specified as an argument to
- the constructor).
- BinarySearchTree allows duplicates -- i.e., a BinarySearchTree may
- contain multiple values that are equal to one another (or multiple
- values with the same key). The ordering of equal values, or
- values with equal keys, is undefined.
- """
- def __init__(self, sort_key=None):
- """
- Create a new empty BST. If a sort key is specified, then it
- will be used to define the sort order for the BST. If an
- explicit sort key is not specified, then each value is
- considered its own sort key.
- """
- self._root = [] # = empty node
- self._sort_key = sort_key
- self._len = 0 # keep track of how many items we contain.
- #/////////////////////////////////////////////////////////////////
- # Public Methods
- #/////////////////////////////////////////////////////////////////
- def insert(self, value):
- """
- Insert the specified value into the BST.
- """
- # Get the sort key for this value.
- if self._sort_key is None:
- sort_key = value
- else:
- sort_key = self._sort_key(value)
- # Walk down the tree until we find an empty node.
- node = self._root
- while node:
- if sort_key < node[_SORT_KEY]:
- node = node[_LEFT]
- else:
- node = node[_RIGHT]
- # Put the value in the empty node.
- if sort_key is value:
- node[:] = [[], [], value]
- else:
- node[:] = [[], [], value, sort_key]
- self._len += 1
- def minimum(self):
- """
- Return the value with the minimum sort key. If multiple
- values have the same (minimum) sort key, then it is undefined
- which one will be returned.
- """
- return self._extreme_node(_LEFT)[_VALUE]
- def maximum(self):
- """
- Return the value with the maximum sort key. If multiple values
- have the same (maximum) sort key, then it is undefined which one
- will be returned.
- """
- return self._extreme_node(_RIGHT)[_VALUE]
- def find(self, sort_key):
- """
- Find a value with the given sort key, and return it. If no such
- value is found, then raise a KeyError.
- """
- return self._find(sort_key)[_VALUE]
- def pop_min(self):
- """
- Return the value with the minimum sort key, and remove that value
- from the BST. If multiple values have the same (minimum) sort key,
- then it is undefined which one will be returned.
- """
- return self._pop_node(self._extreme_node(_LEFT))
- def pop_max(self):
- """
- Return the value with the maximum sort key, and remove that value
- from the BST. If multiple values have the same (maximum) sort key,
- then it is undefined which one will be returned.
- """
- return self._pop_node(self._extreme_node(_RIGHT))
- def pop(self, sort_key):
- """
- Find a value with the given sort key, remove it from the BST, and
- return it. If multiple values have the same sort key, then it is
- undefined which one will be returned. If no value has the
- specified sort key, then raise a KeyError.
- """
- return self._pop_node(self._find(sort_key))
- def values(self, reverse=False):
- """Generate the values in this BST in sorted order."""
- if reverse:
- return self._iter(_RIGHT, _LEFT)
- else:
- return self._iter(_LEFT, _RIGHT)
- __iter__ = values
- def __len__(self):
- """Return the number of items in this BST"""
- return self._len
- def __nonzero__(self):
- """Return true if this BST is not empty"""
- return self._len>0
- def __repr__(self):
- return '<BST: (%s)>' % ', '.join('%r' % v for v in self)
- def __str__(self):
- return self.pprint()
- def pprint(self, max_depth=10, frame=True, show_key=True):
- """
- Return a pretty-printed string representation of this binary
- search tree.
- """
- t,m,b = self._pprint(self._root, max_depth, show_key)
- lines = t+[m]+b
- if frame:
- width = max(40, max(len(line) for line in lines))
- s = '+-'+'MIN'.rjust(width, '-')+'-+\n'
- s += ''.join('| %s |\n' % line.ljust(width) for line in lines)
- s += '+-'+'MAX'.rjust(width, '-')+'-+\n'
- return s
- else:
- return '\n'.join(lines)
- #/////////////////////////////////////////////////////////////////
- # Private Helper Methods
- #/////////////////////////////////////////////////////////////////
- def _extreme_node(self, side):
- """
- Return the leaf node found by descending the given side of the
- BST (either _LEFT or _RIGHT).
- """
- if not self._root:
- raise IndexError('Empty Binary Search Tree!')
- node = self._root
- # Walk down the specified side of the tree.
- while node[side]:
- node = node[side]
- return node
- def _find(self, sort_key):
- """
- Return a node with the given sort key, or raise KeyError if not found.
- """
- node = self._root
- while node:
- node_key = node[_SORT_KEY]
- if sort_key < node_key:
- node = node[_LEFT]
- elif sort_key > node_key:
- node = node[_RIGHT]
- else:
- return node
- raise KeyError("Key %r not found in BST" % sort_key)
- def _pop_node(self, node):
- """
- Delete the given node, and return its value.
- """
- value = node[_VALUE]
- if node[_LEFT]:
- if node[_RIGHT]:
- # This node has a left child and a right child; find
- # the node's successor, and replace the node's value
- # with its successor's value. Then replace the
- # sucessor with its right child (the sucessor is
- # guaranteed not to have a left child). Note: node
- # and successor may not be the same length (3 vs 4)
- # because of the key-equal-to-value optimization; so
- # we have to be a little careful here.
- successor = node[_RIGHT]
- while successor[_LEFT]: successor = successor[_LEFT]
- node[2:] = successor[2:] # copy value & key
- successor[:] = successor[_RIGHT]
- else:
- # This node has a left child only; replace it with
- # that child.
- node[:] = node[_LEFT]
- else:
- if node[_RIGHT]:
- # This node has a right child only; replace it with
- # that child.
- node[:] = node[_RIGHT]
- else:
- # This node has no children; make it empty.
- del node[:]
- self._len -= 1
- return value
- def _iter(self, pre, post):
- # Helper for sorted iterators.
- # - If (pre,post) = (_LEFT,_RIGHT), then this will generate items
- # in sorted order.
- # - If (pre,post) = (_RIGHT,_LEFT), then this will generate items
- # in reverse-sorted order.
- # We use an iterative implemenation (rather than the recursive one)
- # for efficiency.
- stack = []
- node = self._root
- while stack or node:
- if node: # descending the tree
- stack.append(node)
- node = node[pre]
- else: # ascending the tree
- node = stack.pop()
- yield node[_VALUE]
- node = node[post]
- def _pprint(self, node, max_depth, show_key, spacer=2):
- """
- Returns a (top_lines, mid_line, bot_lines) tuple,
- """
- if max_depth == 0:
- return ([], '- ...', [])
- elif not node:
- return ([], '- EMPTY', [])
- else:
- top_lines = []
- bot_lines = []
- mid_line = '-%r' % node[_VALUE]
- if len(node) > 3: mid_line += ' (key=%r)' % node[_SORT_KEY]
- if node[_LEFT]:
- t,m,b = self._pprint(node[_LEFT], max_depth-1,
- show_key, spacer)
- indent = ' '*(len(b)+spacer)
- top_lines += [indent+' '+line for line in t]
- top_lines.append(indent+'/'+m)
- top_lines += [' '*(len(b)-i+spacer-1)+'/'+' '*(i+1)+line
- for (i, line) in enumerate(b)]
- if node[_RIGHT]:
- t,m,b = self._pprint(node[_RIGHT], max_depth-1,
- show_key, spacer)
- indent = ' '*(len(t)+spacer)
- bot_lines += [' '*(i+spacer)+'\\'+' '*(len(t)-i)+line
- for (i, line) in enumerate(t)]
- bot_lines.append(indent+'\\'+m)
- bot_lines += [indent+' '+line for line in b]
- return (top_lines, mid_line, bot_lines)
- """ AN ABSTRACTION OF TREE SORT """
- def abstract_tree_sort(unsorted, BinarySearchTree):
- tree = BinarySearchTree()
- for i in unsorted:
- tree.insert(i)
- return [i for i in tree]
- # 'times' is how many repetitions each algorithm should run
- times = 100
- # 'unique_items' is the number of non-redundant items in the unsorted list
- unique_items = 1003
- # 'order' is an ordered list
- order = []
- for number in range(unique_items):
- order.append(number)
- # Generate the unsorted list
- random_list = order[:]
- random.shuffle(random_list)
- # 'random_set' is used for simple_sort
- random_simple = random_list[:]
- random_set = {item for item in random_simple}
- # A list of all sorted lists for each algorithm
- sorted_lists = [
- simple_sort(random_set, order),
- quick_sort(random_list[:]),
- merge_sort(random_list[:]),
- shell_sort(random_list[:]),
- bubble_sort(random_list[:]),
- heap_sort(random_list[:]),
- insertion_sort(random_list[:]),
- insertion_sort_bin(random_list[:]),
- circle_sort(random_list[:]),
- cocktail_sort(random_list[:]),
- counting_sort(random_list[:], 0, unique_items),
- cycle_sort(random_list[:]),
- gnome_sort(random_list[:]),
- pancake_sort(random_list[:]),
- patience_sort(random_list[:]),
- radix_sort(random_list[:], unique_items),
- selection_sort(random_list[:]),
- abstract_tree_sort(random_list[:], BinarySearchTree),
- sorted(random_list[:])
- ]
- # A set of all sorted lists for each algorithm
- sorted_set = {repr(item) for item in sorted_lists}
- # If only one version of the sorted list exists, True is evaluated
- print 'All algorithms sort identically', len(sorted_set) is 1
- # Sort slices of an unsorted list and record the times in 'time_record'
- time_record = defaultdict(list)
- for length in range(2, unique_items, 10):
- unsorted = random_list[:length]
- # 'unsorted_set' is used for simple_sort
- simple_unsorted = unsorted[:]
- unsorted_set = {item for item in simple_unsorted}
- print '**********', length, '**********'
- print 'simple'
- simple = timeit.timeit(lambda: simple_sort(unsorted_set, order), number=times)
- time_record['Simple Sort'].append(simple)
- print 'quick'
- quick_unsorted = unsorted[:]
- quick = timeit.timeit(lambda: quick_sort(quick_unsorted), number=times)
- time_record['Quick Sort'].append(quick)
- print 'merge'
- merge_unsorted = unsorted[:]
- merged = timeit.timeit(lambda: merge_sort(merge_unsorted), number=times)
- time_record['Merge Sort'].append(merged)
- print 'shell'
- shell_unsorted = unsorted[:]
- shell = timeit.timeit(lambda: merge_sort(shell_unsorted), number=times)
- time_record['Shell Sort'].append(shell)
- print 'bubble'
- bubble_unsorted = unsorted[:]
- bubble = timeit.timeit(lambda: bubble_sort(bubble_unsorted), number=times)
- time_record['In Place Bubble Sort'].append(bubble)
- print 'heap'
- heap_unsorted = unsorted[:]
- heap = timeit.timeit(lambda: heap_sort(heap_unsorted), number=times)
- time_record['In Place Heap Sort'].append(heap)
- print 'insertion'
- insertion_unsorted = unsorted[:]
- insertion = timeit.timeit(lambda: insertion_sort(insertion_unsorted), number=times)
- time_record['In Place Insertion Sort'].append(insertion)
- print 'insertion binary'
- insertion_bin_unsorted = unsorted[:]
- insertion_bin = timeit.timeit(lambda: insertion_sort_bin(insertion_bin_unsorted), number=times)
- time_record['In Place Insertion Sort Binary'].append(insertion_bin)
- print 'circle'
- circle_unsorted = unsorted[:]
- circle = timeit.timeit(lambda: circle_sort(circle_unsorted), number=times)
- time_record['In Place Circle Sort'].append(circle)
- print 'cocktail'
- cocktail_unsorted = unsorted[:]
- cocktail = timeit.timeit(lambda: cocktail_sort(cocktail_unsorted), number=times)
- time_record['In Place Cocktail Sort'].append(cocktail)
- print 'counting'
- counting_unsorted = unsorted[:]
- counting = timeit.timeit(lambda: counting_sort(counting_unsorted, 0, length), number=times)
- time_record['Counting Sort'].append(counting)
- print 'cycle'
- cycle_unsorted = unsorted[:]
- cycle = timeit.timeit(lambda: cycle_sort(cycle_unsorted), number=times)
- time_record['In Place Cycle Sort'].append(cycle)
- print 'gnome'
- gnome_unsorted = unsorted[:]
- gnome = timeit.timeit(lambda: gnome_sort(gnome_unsorted), number=times)
- time_record['Gnome Sort'].append(gnome)
- print 'pancake'
- pancake_unsorted = unsorted[:]
- pancake = timeit.timeit(lambda: pancake_sort(pancake_unsorted), number=times)
- time_record['In Place Pancake Sort'].append(pancake)
- print 'patience'
- patience_unsorted = unsorted[:]
- patience = timeit.timeit(lambda: patience_sort(patience_unsorted), number=times)
- time_record['In Place Patience Sort'].append(patience)
- print 'radix'
- radix_unsorted = unsorted[:]
- radix = timeit.timeit(lambda: radix_sort(radix_unsorted, length), number=times)
- time_record['Radix Sort'].append(radix)
- print 'selection'
- selection_unsorted = unsorted[:]
- selection = timeit.timeit(lambda: selection_sort(selection_unsorted), number=times)
- time_record['Selection Sort'].append(selection)
- print 'tree'
- tree_unsorted = unsorted[:]
- tree_sorted = timeit.timeit(lambda: abstract_tree_sort(tree_unsorted, BinarySearchTree), number=times)
- time_record['Abstract Tree Sort'].append(tree_sorted)
- print 'tim in c'
- tim_unsorted = unsorted[:]
- tim = timeit.timeit(lambda: sorted(tim_unsorted), number=times)
- time_record['Tim in C'].append(tim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement