Skip to content

Instantly share code, notes, and snippets.

@happyduck-git
Created June 5, 2022 11:43
Show Gist options
  • Save happyduck-git/e1897a4b720e0cdd70719df4527ede3f to your computer and use it in GitHub Desktop.
Save happyduck-git/e1897a4b720e0cdd70719df4527ede3f to your computer and use it in GitHub Desktop.
//Recursion 이용한 DFS!
public void dFS(int from, int[][] matrix) {
boolean[] visited = new boolean[matrix.length];
dFSHelper(from, visited, matrix);
}
public void dFSHelper(int from, boolean[] visited, int[][] matrix) {
//방문 여부 체크
if(visited[from]) return;
//첫 방문d이 확인되면 방문 체크!
visited[from] = true;
//연결된 vertices check
for(int i = 0; i < matrix[from].length; i++) {
if(matrix[from][i] == 1) { //연결이 되어 있다면
dFSHelper(i, visited, matrix);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment