\par For each vertex $v$, perform a modified BFS traversal starting a $v$ that stops as soon as level~4 is computed. \par Alternatively, for each vertex $v$, call method DFS$(v,4)$ given below, which is a modified DFS traversal starting at $v$: \par \Algorithm {DFS$(v, i)$} \begin {algorithmic} \IF { {$i > 0$} and {$v$ is not marked} } \STATE Mark $v$. \STATE Print $ v$. \FORALL {vertices $w$ adjacent to $v$} \STATE DFS($w, i-1$). \ENDFOR \ENDIF \end {algorithmic}