Hello everyone,
When writing algorithms operating on sequences, we need to be precise with how we deal with bounds.
For instance, in C, we usually write loops such as:
for (i = 0; i < n; i++) { ... } // exclusive bound
But in other language, we'd write.
for i = 0 to n - 1 // inclusive bound
Similarly, let say we write a binary search function binary_search(arr, i, j)
, we need to to decide whether j
is included or not.
How do you decide which version to use? Do you try to be consistent or do you decide depending on the problem?