used recursion only to compute the number of changes