Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worst case sort time is actually O(n**2), not O(n * log(n)) #1

Open
tanriol opened this issue Jan 6, 2025 · 1 comment
Open

Worst case sort time is actually O(n**2), not O(n * log(n)) #1

tanriol opened this issue Jan 6, 2025 · 1 comment

Comments

@tanriol
Copy link

tanriol commented Jan 6, 2025

Counter-example:

    elif array_type == 'X-shaped':
        random_data = [abs(i - size // 2) * ((-1) ** i) for i in range(size)]

Benchmarking results for this example on my machine

--- X-shaped ---
Array Size |  Merciful Stalin (s) |  Merge Sort (s) |  Quick Sort (s) | Bubble Sort (s) | Insertion Sort (s)
------------------------------------------------------------------------------------------------------------
       100 |             0.000406 |        0.000162 |        0.000385 |        0.000512 |           0.000206
       500 |             0.008444 |        0.000899 |        0.011718 |        0.016313 |           0.006826
     1,000 |             0.042343 |        0.001878 |        0.046340 |        0.069664 |           0.027881
     2,000 |             0.151176 |        0.004479 |        0.192380 |        0.297812 |           0.119710
     5,000 |             0.968564 |        0.014908 |        1.235482 |        2.013621 |           0.799174
    10,000 |             3.840734 |        0.027826 |        4.871039 |        7.971764 |           3.138844
    20,000 |            15.662325 |        0.053856 |       19.865934 |       32.706325 |          13.008377

X_shaped
Merciful_Stalin_Sort_Performance

@tanriol
Copy link
Author

tanriol commented Jan 6, 2025

Actually even the average case results for the random array according to your graphs look more like O(n ** (3/2)), not O(n * log(n))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant