본문 바로가기

[알고리즘개론] - Algorithm

(11)
Radix Sort 개념은 쉽게 이해했지만 구현하는 과정이 신기했던 정렬 알고리즘이였다.
Prim's Algorithm (Time Complexity) 1. O(v^2)인 경우 (v는 정점의 개수) 0) 일단 초기화 for(int i=1; i
Prim's 알고리즘 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980#include using namespace std; int n;int ans;int dist[MAX];bool visit[MAX];vector graph[MAX]; void prim(){ dist[1] = 0; // root visit[1] = true; for(int i=0; i
Heap Sort Heap에는 min heap, max heap이 있다. 이에 대한 정의는 위키피디아! https://ko.wikipedia.org/wiki/%ED%9E%99_(%EC%9E%90%EB%A3%8C_%EA%B5%AC%EC%A1%B0) 힙 (자료 구조) - 위키백과, 우리 모두의 백과사전 위키백과, 우리 모두의 백과사전. 둘러보기로 가기 검색하러 가기 1부터 100까지의 정수를 저장한 최대 힙의 예시. 모든 부모노드들이 그 자식노드들보다 큰 값을 가진다. 힙(heap)은 최댓값 및 최 ko.wikipedia.org 위키피디아 짱..! 아무튼 가장 쉽게 heap sort를 생각할 수 있는 방법은 i) min heap이 있으면 root 원소를 pop한 후 배열에 넣는다 ii) heapify한 후 i반복한다. 시간복..
BinaryHeap time Check 계속 time이 0 뜨는데 이유를 찾아봐야겠음... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 1..
알고리즘 Find_Max 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include #include #include #include #include #include using namespace std; template Type Find_Max(Type* _array, int _n, int& _ret_num_assinments) { Type maxVal = _array[0]; _ret_num_assinments = 1; for (int i = 1; i maxVal) { maxVal = _array[i]; _ret_num_assin..
시간측정 random_device rd; default_random_engine gen(rd()); uniform_int_distribution dist(0, 10 * 1000 * 1000); chrono::time_point startTime = chrono::system_clock::now(); chrono::time_point endTime = chrono::system_clock::now(); chrono::milliseconds timeDiff = chrono::duration_cast(endTime - startTime); double T = timeDiff.count(); printf("Runtime = %d ms\n", (int)T);
알고리즘 Part 4 12345678910111213141516171819202122232425template void Merge_without_Recursion(Type* _array, int _n) { int p, i, _first, _mid, _last; for (p = 1; p
알고리즘 Part 3 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159#include #include #include #i..
알고리즘 Part 2 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136#include #include #include #include #include #include using namespace std; template void Insertion..