How to calculate VC-dimension?
The VC dimension is an estimate for the capability of a binary classifier. If you can find a set of $n$ points, so that it can be shattered by the classifier (i.e. classify all possible $2^n$ labelings correctly) and you cannot find any set of $n+1$ points that can be shattered (i.e. for any set of $n+1$ points there is at least one labeling order so that the classifier can not seperate all points correctly), then the VC dimension is $n$. 

In your case, first consider two points $x_1$ and $x_2$, such that $x_1 &lt; x_2$. Then there are are $2^2=4$ possible labelings 


$x_1:1$, $x_2:1$
$x_1:0$, $x_2:0$
$x_1:1$, $x_2:0$
$x_1:0$, $x_2:1$


All labelings can be achieved through the classifier $h$ by setting the parameters $a&lt;b \in R$ such that


$a&lt;x_1&lt;x_2&lt;b$
$x_1&lt;x_2&lt;a&lt;b$
$a&lt;x_1&lt;b&lt;x_2$
$x_1&lt;a&lt;x_2&lt;b$


respectively. (Actually, $x_1 &lt; x_2$ can be assumed w.l.o.g. but it is enough to find one set that can be shattered.)

Now, consider three arbitrary(!) points $x_1$, $x_2$, $x_3$ and w.l.o.g. assume $x_1&lt;x_2&lt;x_3$, then you can't achieve the labeling (1,0,1). As in case 3 above, the labels $x_1$:1 and $x_2$:0 imply $a&lt;x_1&lt;b&lt;x_2$. Which implies $x_3$ > b and therefore the label of $x_3$ has to be 0. Thus, the classifier cannot shatter any set of three points and therefore the VC dimension is 2.

-

Maybe it becomes clearer with a more useful classifier. Let's consider hyperplanes (i.e. lines in 2D). 

It is easy to find a set of three points that can be classified correctly no matter how they are labeled:



For all $2^3=8$ possible labelings we can find a hyperplane that separates them perfectly. 

However, we cannot find any set of 4 points so that we could classify all $2^4=16$ possible labelings correctly. Instead of a formal proof, I try to present a visual argument:

Assume for now, that the 4 points form a figure with 4 sides. Then it is impossible to find a hyperplane that can separate the points correctly if we label the opposite corners with the same label:

 

If they don't form a figure with 4 sides, there are two "boundary cases": The "outer" points must either form a triangle or all form a straight line. In the case of the triangle, it is easy to see that the labeling where the "inner" point (or the point between two corners) is labeled different from the others can't be achieved:

 
 

In the case of a line segment, the same idea applies. If the end points are labeled differently than one of the other points, they cannot be separated by a hyperplane. 

Since we covered all possible formations of 4 points in 2D, we can conclude that there are no 4 points that can be shattered. Hence, the VC dimension must be 3.