Re:Sleeping Through the Technical Interview (2022)
by xena on Friday July 07, 2023 @03:27PM
(#36637099)
The constant is the biggest number in the array
[ Parent
| on HN ]
Re:Sleeping Through the Technical Interview (2022)
by NotYourLawyer on Friday July 07, 2023 @03:33PM
(#36637176)
If runtime depends on the input, it’s not constant time.
Re:Sleeping Through the Technical Interview (2022)
by addaon on Friday July 07, 2023 @05:21PM
(#36638474)
It's constant with regards to the length of the input array, which is the usual metric for sort algorithm performance. That is, d(runtime)/d(len(input)) can be constant, even though d(runtime)/d(max(input)) is not, if you assume that len(input) is independent from max(input) (which is inconsistent with input having uniformly distributed random members, which is probably the more common assumption).
Re:Sleeping Through the Technical Interview (2022)
by recursive on Friday July 07, 2023 @06:51PM
(#36639307)
It's constant with respect to the number of elements, just not the maximum magnitude of those elements.
Re:Sleeping Through the Technical Interview (2022)
by upon_drumhead on Friday July 07, 2023 @07:05PM
(#36639432)
I don't see how it is. Different, but the same number, of elements is a different time. There's no constant time between [0, 1] and [0, 10], both having two elements.
Re:Sleeping Through the Technical Interview (2022)
by squeaky-clean on Friday July 07, 2023 @07:12PM
(#36639478)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
is just as fast as
[9]
If you really want to make it strictly constant time, just append INT32_MAX to the end of the array before sorting, and then pop it after.
Re:Sleeping Through the Technical Interview (2022)
by libealistand on Saturday July 08, 2023 @03:02AM
(#36642047)
Oh yeah, because assumin maximum values in your domain doesn't move all algorithms into constant time and renders complexity theory void.
Re:Sleeping Through the Technical Interview (2022)
by squeaky-clean on Saturday July 08, 2023 @08:47PM
(#36650276)
It doesn't though. How would merge sort become constant time if you assume a maximum value? It's also a joke...
Re:Sleeping Through the Technical Interview (2022)
by libealistand on Monday July 10, 2023 @02:05AM
(#36662676)
The main "value" in the domain of sorting problems is the number of elements in your collection.
A subproblem also considers the elements to be integers, then they become another "value" domain. (But in general, sorting problems only need their elements to be comparable, not necessarily integers.)