algorithm - haskell quick sort complexity? -


i run below quick sort haskell function (using merge , sort algorithm):

qsort []=[] qsort (x:xs) =   qsort smaller ++ [x] ++ qsort larger           smaller = [a | <- xs , a<x ] -- edit       larger  = [b | b <- xs , b>=x ] 

in order test runtime bit big amount of data, run below code:

qsort [100000,99999..0] 

it takes till 40 min , still running! list of 100,000 not big, so:

  1. how handle data billion of data?
  2. is sort algorithm(merge , sort) takes less time in other language c#, python...is problem in haskell language
  3. how predict runtime of algorithm using complexity?

the worst case time of quicksort n2. implementation uses first element pivot, results in worst-case performance when input sorted (or sorted in reverse).

to quicksort perform @ expected complexity of n log n, need either randomized pivot selection, or randomly shuffle input before sorting.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -