basis matrix DFS search