Nodal deficiency, spectral flow, and the Dirichlet-to-Neumann map