How to know the filter order Could anyone explain to me how can I know the filter order based on algorithm?

For example:


$y[n] = \frac12 x[n] – x[n–1] + \frac12 x[n–2]$ has order filter 2.
$y[n] =2 x[n] – x[n–1] + y[n–1]$ has order filter 1.
$y[n] =2 x[n] – x[n–1] + x[n–2]+ y[n–1] + y[n–2]$ has order filter 2.


Why?
If the discrete-time filter is described by the linear difference equation

$$y[n]=\sum_{k=1}^{K}a_ky[n-k]+\sum_{m=0}^{M}b_mx[n-m]$$

(with $a_K\neq 0$ and $b_M\neq 0$), the filter order is given by
$\max\{K,M\}$, i.e., by the maximum delay necessary to implement the filter.