JPDev@programming.dev to Programmer Humor@programming.dev · 7 months agoReturns a sorted list in O(1) timeprogramming.devimagemessage-square17fedilinkarrow-up112arrow-down10
arrow-up112arrow-down1imageReturns a sorted list in O(1) timeprogramming.devJPDev@programming.dev to Programmer Humor@programming.dev · 7 months agomessage-square17fedilink
minus-squaremcmodknower@programming.devlinkfedilinkarrow-up2·7 months agoyou can even have a case where you return the first element of the list if the list is not empty, and it will still be O(1).
minus-squaremurtaza64@programming.devlinkfedilinkarrow-up1·7 months agoyou can make it sort the first k elements and it will still be O(1). Set k high enough and it might even be useful
minus-squarexmunk@sh.itjust.workslinkfedilinkarrow-up2·7 months agoI set k to 50,000,000,000… that’s more items than my shitty computer can fit in memory (including swsp) but I am now happy to celebrate my O(1) algorithm.
you can even have a case where you return the first element of the list if the list is not empty, and it will still be O(1).
you can make it sort the first k elements and it will still be O(1). Set k high enough and it might even be useful
I set k to 50,000,000,000… that’s more items than my shitty computer can fit in memory (including swsp) but I am now happy to celebrate my O(1) algorithm.