Dijkstra's preferred interval notation
Dijkstra's argument that numbering should start at zero begins with an analysis of a subsequence of natural numbers, namely , and what interval notation should be preferred most to denote this sequence. Exploring his argument in more detail allows for greater understanding as to why the half-interval notation is to be preferred in a variety of programming contexts (e.g., implementing sliding windows).
Dijkstra's argument (explored)
Dijkstra's original argument may be viewed in its entirety below, but for the sake of clarity, let's consider the full subsequence of natural numbers denoted by (the index of each value is also included as if the values were part of a 0-indexed array):
# index: 0 1 2 3 4 5 6 7 8 9 10
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Dijkstra presents the following four conventions that are open to us to denote the subsequence of natural numbers above:
- (a)
- (b)
- (c)
- (d)
Using interval notation, the expressions above may be captured succinctly as follows:
- (a) : half-open interval
- (b) : half-open interval
- (c) : closed interval
- (d) : open interval
Let's now consider, in turn, various elements of Dijkstra's argument for a better understanding of what he was trying to communicate and why option (a)
is to be preferred. Each section will depict the desirable property by means of an excerpt from Dijkstra's original note (along with the preferred conventions to satisfy that property) followed by a discussion to solidify why the preferred conventions are actually preferred.
Difference between bounds equals length of subsequence
The observation that conventions a) and b) have the advantage that the difference between the bounds as mentioned equals the length of the subsequence is valid.
Preferred:
(a)
and(b)
First, note that the length of the subsequence of natural numbers
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
is (i.e., there are numbers in the subsequence above). Now consider the difference in value between the upper and lower bound for each of the previously mentioned conventions:
- (a)
- (b)