开发者

how to sort an array in C in one cycle?

开发者 https://www.devze.com 2023-01-29 07:22 出处:网络
Is there 开发者_开发技巧any algorythm to sort an array of float numbers in one cycle?If you mean one pass, then no. Sorting generally requires either O(N log N). Single-pass implies O(N).

Is there 开发者_开发技巧any algorythm to sort an array of float numbers in one cycle?


If you mean one pass, then no. Sorting generally requires either O(N log N). Single-pass implies O(N).

Radix sort takes O(N*k) with average key-length k. Even though it's linear time, it requires multiple passes. It is also not usually suitable for sorting floats.


Take a laptop with a quicksort program on it. Then put the laptop on a unicycle. Tada! Sorting in one cycle.


check Counting sort it runs in O(N + M) time where N is the input array size and M is the sorting array size


There are some sorting algorithms that are O(n) in the best-case. See here.


No, there is no algorithm that is O(n). Possibly using as many parallel computers as there are elements in your array or using quantum computers, but if you want O(n) now on a regular computer, you can forget about it.


No.

<aside>@codinghorror: why must my post have >= 15 characters?</aside>


Sorting algorithm "in one cycle" - I believe you mean algorithm with linear complexity. In addition to these answers you can also check Bucket Sort Algorithm. It has average performance O(n+k).

0

精彩评论

暂无评论...
验证码 换一张
取 消