1 #-*-coding:utf8-*-2 ImportRandom3A=[]4b=[]5 defInit_array ():6 forIinchRange (10000):7v = random.randint (1,10000)8 A.append (v)9 B.append (v)Ten One #bubbling A defSort_array (a): - forIinchRange (len (a)): - forJinchRange (i+1, Len (a)): the ifA[i] >A[j]: -I_v =A[i] -a[i]=A[j] -a[j]=I_v + - + #Quick Line A defQuick_sort (a,left,right): at ifLeft <Right : -Key =A[left] -Low = Left -High = Right - whilelow<High : - whileLow anda[high]>=Key: inHigh-=1 -A[low] =A[high] to whileLow anda[low]<=Key: +Low+=1 -a[high]=A[low] thea[low]=Key *Quick_sort (a,left,low-1) $Quick_sort (a,low+1, right)Panax Notoginseng - the Init_array () + A Print "a", Len (a) the Print "b", Len (b) + - Sort_array (a) $Quick_sort (B,0,len (b)-1) $ - PrintA,len (a) - PrintB,len (b)
Save the above as sort.py and then:
Python-m CProfile sort.py
Bubble time Complexity O (n^2)
Worst O (n^2), average O (N*LGN)
Python bubbles and Clippers, not much to say "boring"