|
|
|
|
|
by sid6376
5397 days ago
|
|
Apologies if this appears dumb. After going through the link I still could not understand why is it ok to exclude the upper bound while including the lower bound? Is it because the lower bound is fixed as 0 is the smallest natural number? Or is there some other reason. |
|
The first is so that the number of elements in the array/list/vector/collection is given by upper-lower.
The second is so that successive intervals re-use the same number, the upper bound of one becoming the lower bound of the next.
This is python we can have:
With the repeated numbers we know that all elements of L have been included. Further, we know that given: ... then (provided L had at least "end" elements to start with) the resulting length is end-start. If you included the end point then the length would be end-start+1 which is fertile ground for fence-post errors.