1109
submitted 11 months ago by yttrium to c/196
you are viewing a single comment's thread
view the rest of the comments
[-] Cralder@feddit.nu 10 points 11 months ago

Not necessarily. If you know that your pants are at the bottom then you can just plunge your hand into the pile and grab them without any searching.

[-] yetAnotherUser@feddit.de 5 points 11 months ago

Thay depends on the size of the pile, there could be a lot of weight and instability above the pants and you'll have to pull them out à la Jenga or carefully rearrange the stack.

Since the amount of rearranging increases for larger n (imagine a pile reaching the ceiling), searching is in ω(1).

[-] Cralder@feddit.nu 7 points 11 months ago

I feel like this metaphor is getting out of hand

[-] rasensprenger@feddit.de 6 points 11 months ago

As the volume of the room is finite, even "exponential" or worse search algorithms will complete in constant time.

[-] yetAnotherUser@feddit.de 3 points 11 months ago

<.<

Well, there's only finitely many atoms in the universe, do all algorithms therefore have constant time?

Although you could argue for very large amounts of clothes my method of throwing clothes on the floor starts performing worse due to clothes falling on the same spot and piling up again.

Unless you extend your room. Let's take a look at the ✨amortized✨time complexity.

[-] rasensprenger@feddit.de 4 points 11 months ago

Well landau notation only describes the behaviour as an input value tends to infinty, so yes, every real machine with constant finite memory will complete everything in constant time or loop forever, as it can only be in a finite amount of states.

Luckily, even if our computation models (RAM/TM/...) assume infinite memory, for most algorithms the asymptotic behaviour is describing small-case behaviour quite well.

But not always, e.g. InsertionSort is an O(n^2) algorithm, but IRL much faster than O(n log n) QuickSort/MergeSort, for n up to 7 or so. This is why in actual programs hybrid algorithms are used.

this post was submitted on 19 Oct 2023
1109 points (100.0% liked)

196

16246 readers
2361 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS