BFS(너비 우선 탐색)
namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; List[] adj2 = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1, 4 }, new List{ 3, 5 }, new List{ 4 }, }; public void BFS(int start)//길찾기에서 쓰임 { bool[] found = new bool[6]; int[] parent =..
2023. 7. 16.
DFS(깊이 우선 탐색)
namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; List[] adj2 = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1 }, new List{ 5 }, new List{ 4 }, }; // 1) 우선 now부터 방문하고. // 2) now와 연결된 정점들을 하나씩 확인해서, // [ 아직 미발견(미방문)상태라면] 방문한다. public v..
2023. 7. 16.
그래프 생성
namespace Exercise { internal class Program { class Graph { int[,] adj = new int[6, 6] {{0,1,0,1,0,0}, {1,0,1,1,0,0}, {0,1,0,0,0,0}, {1,1,0,0,1,0}, {0,0,0,1,0,1}, {0,0,0,0,1,0}}; }; List[] list = new List[] { new List{ 1, 3 }, new List{ 0, 2, 3 }, new List{ 1 }, new List{ 0, 1, 4 }, new List{ 3, 5 }, new List{ 4 }, }; static void Main(string[] args) { //DFS(Depth First Search 깊이 우선 탐색) //BFS(Bre..
2023. 7. 16.