Computing time complexity in C [closed]

For comparison sorting we consider the number of comparisons, sorting complicated objects this usually dominates.

Your outer loop always runs count times, your inner loop always runs on average ~count / 2 times. Every iteration of the inner loop always does one comparison.

Hence you get best, worst and average case is count * count / 2 which means all of them do O(n²) and Ω(n²) and θ(n²) comparisons (having n = the count parameter).

It is not the worst sorting algorithm imaginable if it works (I didn’t care to test), but best comparison sorting algorithms achieve O(n log n) worst case. In practice a hybrid algorithm like Timsort would always outperform your code except for a handful of items.

Leave a Comment