This is a slightly broader concept in mathematics and applies to more than just vectors.
Imagine a continuous number line:
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4
|
Now, let's say I want a particular set of numbers in a certain range.
I want a range representing every number from 0 to 3.
===================
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4
|
0.1, 2, and 2.9 are in the range.
-1, -0.1, 4, and 3.1 are all not in this range.
But what about right at 0 or right at 3? This is where [] vs () comes into play.
If I say that the range is [0, 3], this means that 0 and 3 are included in the range.
If I say that the range is (0, 3], this means that 0 is not included in the range, but 3 is.
If I say that the range is [0, 3), this means that 0 is included in range, but 3 is not.
"Not in the range" can be represented with an open circle (white), while "in the range" can be represented with a closed circle (black).
[0, 3]:
●=================●
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4 |
(0, 3]:
o=================●
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4 |
[0, 3):
●=================o
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4 |
(0, 3):
o=================o
+-----+-----+-----+-----+-----+-----+-----+
-1 0 1 2 3 4 |
If we're only dealing with integers, it's even simpler.
kmce wrote: |
---|
1. What is a half open sequence? |
Half-open sequence is when the beginning element of the sequence is included, but the last element of the sequence is not.
kmce wrote: |
---|
Why is a vector notation [0:v.size()) |
It means the first index 0, is included, but the index that is the size of the vector itself is not.
e.g. [0:5), for discrete sequences, means the sequence "0, 1, 2, 3, 4".
If you have a vector of size 5, then its valid elements are 0, 1, 2, 3, 4. vector[5] is not a valid element of the vector.