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:
- how handle data billion of data?
- is sort algorithm(merge , sort) takes less time in other language c#, python...is problem in haskell language
- 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
Post a Comment