Anonymous user
Compare sorting algorithms' performance: Difference between revisions
Compare sorting algorithms' performance (view source)
Revision as of 07:47, 24 December 2007
, 16 years agocouple examples of sorting routine
m (Quick sort -> Quicksort) |
(couple examples of sorting routine) |
||
Line 10:
Consider at least two different sorting function (different algorithms or/and different implementation of the same algorithm).
For example, consider [[Bubble Sort]], [[Insertion sort]], [[Quicksort]] or/and implementations of [[
Where possible, use existing implementations.
Line 28:
'''Interpreter:''' [[Python]] 2.5
[[Category:Python]]
===A couple examples of sorting routines===
def builtinsort(x):
x.sort()
def partition(seq, pivot):
low, middle, up = [], [], []
for x in seq:
if x < pivot:
low.append(x)
elif x == pivot:
middle.append(x)
else:
up.append(x)
return low, middle, up
#
def qsortranpart(seq):
size = len(seq)
if size < 2: return seq
low, middle, up = partition(seq, seq[random.randrange(size)])
return qsortranpart(low) + middle + qsortranpart(up)
===Sequence generators===
Line 53 ⟶ 73:
Ns, Ts)
</code>
Where ''writedat()'' is defined in the [[Write float arrays to a text file]]
===Plot timings===
{{library|matplotlib}}
|