this post was submitted on 08 Nov 2024
673 points (98.3% liked)

Programmer Humor

19497 readers
1291 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] 1boiledpotato@sh.itjust.works 8 points 17 hours ago (1 children)

And the time complexity is only O(1)

[–] voldage@lemmy.world 13 points 14 hours ago (1 children)

I don't think you can check if array of n elements is sorted in O(1), if you skip the check though and just assume it is sorted now (have faith), then the time would be constant, depending on how long you're willing to wait until the miracle happens. As long as MTM (Mean Time to Miracle) is constant, the faithfull miracle sort has O(1) time complexity, even if MTM is infinite. Faithless miracle sort has at best the complexity of the algorithm that checks if the array is sorted.

Technically you can to down to O(0) if you assume all array are always sorted.

[–] 1boiledpotato@sh.itjust.works 1 points 13 hours ago

Oh yeah, I didn't think about the time that it takes to check if it's sorted. The sorting time is constant though