Permutation(순열) Algorithm
== Permutation(순열) Algorithm ==- 순차적으로 swapping 해주네!! code def perm(input, i): if i == len(input)-1: print(input) else: for j in range(i, len(input)): input[i], input[j] = input[j], input [i] perm(input, i+1) input[i], input[j] = input[j], input [i] perm([1,2,3], 0) - 사용예 - 여행할 때, 방문 순서 경우의 수! source-code : The-Greference : 상상개발자
BFS(Breadth First Search)
== BFS(Breadth First Search) == vertexList = ['0', '1', '2', '3', '4', '5', '6'] edgeList = [(0,1), (0,2), (1,0), (1,3), (2,0), (2,4), (2,5), (3,1), (4,2), (4,6), (5,2), (6,4)] adjacencyList = [[] for vertex in vertexList] for edge in edgeList: adjacencyList[edge[0]].append(edge[1]) adjacencyList = [[1,2], # vertex 0 [0,3], # vertex 1 [0,4,5], # vertex 2 [1], # vertex 3 [2,6], # vertex 4 [2], # ..
DFS(Depth First Search) / DFS to find cycle in graph
== Depth First Search(깊이 우선 탐색) == vertexList = ['0', '1', '2', '3', '4', '5', '6'] edgeList = [(0,1), (0,2), (1,0), (1,3), (2,0), (2,4), (2,5), (3,1), (4,2), (4,6), (5,2), (6,4)] adjacencyList = [[] for vertex in vertexList] for edge in edgeList: adjacencyList[edge[0]].append(edge[1]) adjacencyList = [[1,2], # vertex 0 [0,3], # vertex 1 [0,4,5], # vertex 2 [1], # vertex 3 [2,6], # vertex 4 [2],..
자료구조 Graph
== Graph 기본 개념 정리 == - Direct Graph - vertax 와 edge 가 있으면 Graph 라고 한다 - 방향성이 있으니 Direct Graph - Undirect Graph - 방향성이 없다. - Weighted Graph - edge에 cost가 있을 때 - Vertex List vertaxList = ['0', '1', '2', '3', '4', '5'] - Edge List edgeList = [(0,1), (1,0), (1,2), (1,3), (2,1), (3,1), (3,4), (4,3), (4,5), (5,4)] - Undirect graph 이니 양쪽 방향 다 있지. - Adjacency List adjacencyList = [[1], [0,2,3], [1], [1,..