4

The median of a singleton set is the element itself. The median of a set with two elements is the average of the elements.

What should a machine return when required the median of an empty set?

HAL9000
  • 205
  • 5
    It's not defined. – Rushabh Mehta Nov 25 '19 at 21:47
  • @DonThousand would you have some reference about it? I mean: I understand that is undefined and I agree, but I'd like something more formal – HAL9000 Nov 25 '19 at 21:49
  • (By the way, my car license plate is the same as your screen name.) – David G. Stork Nov 25 '19 at 21:50
  • @DavidG.Stork lol. Good choice – HAL9000 Nov 25 '19 at 21:51
  • 1
    (Do a websearch on my name and "HAL 9000".) – David G. Stork Nov 25 '19 at 21:52
  • 6
    I'm sorry, Dave. I'm afraid I can't do that. – Daniel Fischer Nov 25 '19 at 21:54
  • I don't know whether the answer should be the same for median and mean, but the latter case is discussed at https://math.stackexchange.com/q/909395/16490 – ziggurism Nov 25 '19 at 21:58
  • The question has no answer. It is similar to asking "+ = ?". – herb steinberg Nov 25 '19 at 22:11
  • What should a machine return when required the median of a banana? If the input is not in the domain of a function, there is no defined output. – MPW Nov 25 '19 at 22:13
  • @MPW the median of a banana is the banana itself. – HAL9000 Nov 25 '19 at 22:22
  • 1
    Part of the contract for a computer program specifies what should happen when the input is faulty for some reason. Possible strategies: return an error code, raise an exception, silently fail, crash. In any of these scenarios you might print a message first somewhere – Ethan Bolker Nov 25 '19 at 22:31
  • What would you have it do if it were asked to return the mean of an empty set, rather than the median? It's not defined. – MJD Nov 25 '19 at 22:48
  • @HAL9000 : No, I think it’s banana/2, or banana split :-p – MPW Nov 26 '19 at 02:54
  • @EthanBolker sorry but I don't believe that crash and silently fail are viable strategies. But the overall comment makes sense: it's all about input validation. – HAL9000 Nov 26 '19 at 14:59
  • @HAL9000 Of course they are not viable. Neither, really, is just printing something since the call might be embedded somewhere. Sad how common those nonstrategies are.. But I wonder if they are not better than guessing what the caller might want - perhaps $0$ in this case - and returning that. Then the caller proceeds in ignorance. – Ethan Bolker Nov 26 '19 at 15:03
  • @EthanBolker well, in fact my question came from the fact that my colleague decided arbitrarly to return +infinity when the set is empty :D – HAL9000 Nov 26 '19 at 19:25
  • 1
    @HAL9000 “If a function is called with the wrong arguments, the best thing it can do is to drop dead immediately, pausing only long enough to gasp out a message explaining what is wrong, and incriminating its caller.” (https://blog.plover.com/prog/perl/do-not-2.html) Your co-worker is not doing anyone a favor by silently returning a nonsensical result to a nonsensical question. The bug is in the function that asks for the median of an empty set. Returning a bogus answer will just make the bug that much harder to find. The article also addresses your "crash is not viable" suggestion. – MJD Nov 27 '19 at 13:47

1 Answers1

5

The median of a set $A$ is the value $\tilde\mu$ such that the sets $\{x \in A : x \lt \tilde\mu\}$ and $\{x \in A : x \gt \tilde\mu\}$ have the same number of elements, and if there is not one unique such value then it is the one that is the arithmetic mean of the largest element of the first set and the smallest element of the second.

If $A = \emptyset$, then the partitioned sets are both empty, and so do not have largest or smallest elements, so there is no such value, and so the median is undefined.

ConMan
  • 24,300
  • This definition of the median does not make a sense unless $A$ is a subset of some ordered set. For example you cannot do this with complex numbers or some arbitrary set ${a, b}.$ Now, the next question is "does the empty set has a partial ordering on it?" – Bumblebee Mar 22 '20 at 23:50
  • That is true, I wrote this answer on the assumption that we are specifically looking at sets of real numbers (since that's what the median is usually calculated on). That said, if we're not in such a space, then the median of A is still undefined but for a different reason! – ConMan Mar 23 '20 at 00:37
  • I was thinking about possible generalizations of your answer for generalized medians. The interesting point is the empty set not only a subset of reals but any set :). BTW nice answer. – Bumblebee Mar 23 '20 at 00:50