/* 탐색을 할 때 너비를 우선으로 하여 탐색을 수행하는 탐색 알고리즘. 맹목적인 탐색. 치단 경로를 찾아준다는 점에서 최단 길이를 보장해야 할 때 많이 사용. 큐를 사용. 그 자체로는 큰 의미가 없고, 다른 알고리즘에 적용되었을 때 의미가 있음. */ #include #include #include using namespace std; int number = 7; //원소의 갯수 int c[7]; //방문처리를 위한 배열 vector a[8]; //인덱스를 1부터 처리할려고 8. void bfs(int start) { queue q; q.push(start); c[start] = true; while (!q.empty()) { int x = q.front(); q.pop(); cout
Algorithm 검색 결과
//범위조건이 있는 경우에 한해서 굉장히 빠른 알고리즘. //시간복잡도 O(N). //크기를 기준으로 갯수를 세는 것. #include using namespace std; int main() { int count[5] = { 0, }; int array[30] = { 1, 3, 2, 4, 3, 2, 5, 3, 1, 2, 3, 4, 4, 3, 5, 1, 2, 3, 5, 2, 3, 1, 4, 3, 5, 1, 2, 1, 1, 1 }; for (int i = 0; i < 30; i++) { count[array[i] - 1]++; } for (int i = 0; i < 5; i++) { for (int j = 0; j < count[i]; j++) { cout
//힙정렬은 힙 트리 구조를 이용하는 정렬방법. //시간복잡도 O(N*logN). #include using namespace std; int number = 9; int heap[9] = { 7, 6, 5, 8, 3, 5, 9, 1, 6 }; int main() { //힙 생성 알고리즘(Heapify) for (int i = 1; i < number; i++) { int c = i; do { int root = (c - 1) / 2; if (heap[root] < heap[c]) { int temp = heap[root]; heap[root] = heap[c]; heap[c] = temp; } c = root; } while (c != 0); } //크기 줄여가며 반복적으로 힙 구성 for (int i..