본문 바로가기

C++197

[A* & Heap] Chapter 04. A* 길찾기 알고리즘 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/b09c4e2a981618692e07cbbad085fe32267f16d9 A* 길찾기 알고리즘 · developeSHG/Data_Structure-Algorithm@b09c4e2 developeSHG committed Aug 10, 2023 github.com 그럼 이전까지 학습한걸로 예전에 진행했던 Maze(미로)에서 길찾기 알고리즘을 좀 더 최적화해보자. 다익스트라와 BFS를 생각해보면 시작점의 개념은 있었지만, 뚜렷하게 목적지란 개념은 없었다. 물론 탐색과정에서 목적지를 발견하면 멈추라는 명령을 내리긴 했지만, 그건 어디까지나 중간에 탐색하다 멈추는 개념이었지 처음부터 목.. 2023. 8. 8.
[A* & Heap] Chapter 03. 우선순위 큐 구현 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/f9452fae763d2a5c6f359a528f94a64bcebf502c 우선순위 큐 구현 · developeSHG/Data_Structure-Algorithm@f9452fa developeSHG committed Aug 10, 2023 github.com 우선순위 큐에 push와 pop을 할 때, 시간복잡도는 O(log n)이다. 우선순위 큐는 힙 tree 구조로 이루어져 있기 때문에, 데이터를 삽입하거나 뺐을 때, 비교 연산이 최대 tree의 높이까지 발생하기 때문이다. #include #include #include #include #include using namespa.. 2023. 8. 8.
[A* & Heap] Chapter 02. 힙 이론 우선순위 큐는 힙 트리 구조로 이뤄졌다. 힙트리도 이진트리의 일종이다. - 이진 트리의 개념 각 노드가 최대 두 개의 자식 노드를 가지는 트리 - 이진 검색 트리 특징 1) 왼쪽을 타고 가면 현재 값보다 작다 2) 오른쪽을 타고 가면 현재 값보다 크다 - 이진 검색 트리 문제 그냥 무식하게 추가하면, 한쪽으로 기울어져서 균형이 깨진다 트리 재배치를 통해 균형을 유지하는 것이 과제 (AVL, Red-Black) - 힙 트리 특징 1. [부모 노드]가 가진 값은 항상 [자식 노드]가 가진 값보다 크다. 2. 노드 개수를 알면, 트리 구조는 무조건 확정할 수 있다. - 힙 트리 구현 배열을 이용해서 힙 구조를 바로 표현할 수 있다. 1) i번 노드의 왼쪽 자식은 [(2 * i) + 1] 번 2) i번 노드의 .. 2023. 8. 8.
[A* & Heap] Chapter 01. 트리 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/ac4f9cf68e09fad3391232e069649d597289e58c Tree · developeSHG/Data_Structure-Algorithm@ac4f9cf developeSHG committed Aug 8, 2023 github.com 트리의 개념 계층적 구조를 갖는 데이터를 표현하기 위한 자료구조 노드(Node) : 데이터를 표현 간선(Edge) : 노드의 계층 구조를 표현하기 위해 사용 위의 Tree 구조를 코드로 표현해보자. #include #include #include #include #include using namespace std; using NodeR.. 2023. 8. 8.
[Graph] Chapter 05. 다익스트라(Dijkstra) 알고리즘 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/ed3f5772f67f98efb67841c1795909f85c76211f 다익스트라(Dijkstra) 알고리즘 구현 · developeSHG/Data_Structure-Algorithm@ed3f577 developeSHG committed Aug 8, 2023 github.com 시작점에서 목적지까지 가는 정점의 간선에 비용이 있다고 가정해보면 적용할 수 있는게 다익스트라 알고리즘이다. 내가 먼저 발견한 순서대로 방문을 하는게 BFS라면, 다익스트라는 인접한 정점을 인지한 후, 방문할 수 있도록 등록은 한다. 근데 각 정점으로 갈 때, 비용은 얼마나 드는지 가중치를 같이 포함해.. 2023. 8. 8.
[Graph] Chapter 04. BFS를 이용한 길찾기 구현 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/ce84719bc1e67974dda74fb833ac50e526c8fe19 BFS를 이용한 길찾기 구현 · developeSHG/Data_Structure-Algorithm@ce84719 developeSHG committed Aug 8, 2023 github.com 이전 글에서 구현한 BFS를 토대로 Maze(미로) 글에 길찾기를 적용했던 우수법을 BFS로 교체해보자. 이전에 BFS를 구현할 때, Vertex라는 점을 만든 다음 인접리스트 혹은 인접행렬을 토대로 관리했었다. 대부분의 경우에는 실제 정점정보와 인접정보를 구분해서 만드는 것이 조금 더 활용하기 편하다고 했다. 하지.. 2023. 8. 8.
[Graph] Chapter 03. BFS (너비 우선 탐색) GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/b415c0586aecf03641d3eb30fb58d34f1ccdab96 BFS (너비 우선 탐색) 구현 · developeSHG/Data_Structure-Algorithm@b415c05 developeSHG committed Aug 8, 2023 github.com 길찾기를 할 때, 한 경로로 깊이 탐색하는 DFS 보다 가까운 것을 먼저 탐색하는 BFS를 더 우선 사용. #include #include #include #include #include using namespace std; // [ ][ ][ ][ ][ ][ ][ ][ ] // DFS (Depth First S.. 2023. 8. 8.
[Graph] Chapter 02. DFS (깊이 우선 탐색) GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/ee1c8ba520c4c868b8bf032b18231b882f72723e DFS (깊이 우선 탐색) 구현 · developeSHG/Data_Structure-Algorithm@ee1c8ba developeSHG committed Aug 8, 2023 github.com #include #include #include #include #include using namespace std; // [ ][ ][ ][ ][ ][ ][ ][ ] // DFS (Depth First Search) 깊이 우선 탐색 // BFS (Breadth First Search) 너비 우선 탐색 struc.. 2023. 8. 8.
[Graph] Chapter 01. 그래프 GitHub : https://github.com/developeSHG/Data_Structure-Algorithm/commit/a371f42dd4ae7aea9e445bcca06d4ebff3d9e1de 그래프 구현 · developeSHG/Data_Structure-Algorithm@a371f42 developeSHG committed Aug 8, 2023 github.com 그래프의 개념 [현실 세계의 사물이나 추상적인 개념 간]의 [연결 관계]를 표현 정점(Vertex) : 데이터로르 표현 (사물, 개념 등) 간선(Edge) : 정점들을 연결하는데 사용 위 사진의 그래프를 3가지 방법으로 만들어보자. #include #include #include #include #include using names.. 2023. 8. 8.
[Programmers] (완전탐색) Lv 2. 전력망을 둘로 나누기 https://school.programmers.co.kr/learn/courses/30/lessons/86971 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr const bfs = (graph, pivot, visited, vistedDuplication) => { const queue = [pivot]; let cnt = 0; while (queue.length) { const dest = queue.shift(); if (vistedDuplication[dest]) return Infinity; (visited[dest] = true), ++cnt;.. 2023. 8. 8.