/cpp_Algorithm_implementation

๐Ÿ““ C++ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„์ฒด ๐Ÿ““

Primary LanguageC++

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ •๋ฆฌ ๐Ÿ™‚


ํ˜น์‹œ๋‚˜ ํ‹€๋ฆฐ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ์ง€์ ํ•ด์ฃผ์„ธ์š”!! (๋‚œ์ด๋„ ์ˆœ์„œ X, ๋‚ด๊ฐ€ ๊ณต๋ถ€ํ•œ ์ˆœ์„œ O)


์ˆœ์„œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‹œ๊ฐ„ ๋ณต์žก๋„
01 ์„ ํƒ ์ •๋ ฌ Select Sort O(N2)
02 ๋ฒ„๋ธ” ์ •๋ ฌ Bubble Sort O(N2)
03 ์‚ฝ์ž… ์ •๋ ฌ Insertion sort O(N2)
04 ํ€ต ์ •๋ ฌ Quick Sort ํ‰๊ท : O(N*logN), ์ตœ๋Œ€: O(N2)
05 ๋ณ‘ํ•ฉ ์ •๋ ฌ Merge Sort O(N*logN)
06 STL::Sort ์‚ฌ์šฉ sortMethod O(N*logN)
07 ํž™ ์ •๋ ฌ Heap Sort O(N*logN)
08 ๊ณ„์ˆ˜ ์ •๋ ฌ Counting Sort O(N)
09 ์Šคํƒ ๊ตฌํ˜„ stack
10 ํ ๊ตฌํ˜„ Queue
11 BFS(๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰) Breath First Search O(V2)
12 DFS(๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰) Depth First Search O(V2)
13 ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ Union Find O(logE)
14 ์ตœ์†Œ ์ŠคํŒจ๋‹ ํŠธ๋ฆฌ Kruskal Algorithm O(E*logE)
15 ๋ฐ”์ด๋„ˆ๋ฆฌ ํŠธ๋ฆฌ Binary Tree
16 ๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ Dynamic Programming O(N)
17 ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด Prime Number O(N*logN*logN)
18 ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜ Dijkstra Algorithm O(E*V*logV)
19 ๊ด„ํ˜ธ๋ฌธ์ œ Parentheses
20 ๋ถ„ํ•  ์ •๋ณต Quad Tree O(N*logN)
21 ๋ฐฑํŠธ๋ž˜ํ‚น BackTracking O(2N)
22 ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜2 Dijkstra Algorithm2 O(E*logV)
23 ์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ• Ecuild
24 ์ด๋ถ„ ๋งค์นญ Bipartite Matching O(VE)
25 KMP ์•Œ๊ณ ๋ฆฌ์ฆ˜ KMP Algorithm O(N)
26 ์œ„์ƒ ์ •๋ ฌ Topology Sort O(V+E)
27 ์„ธ๊ทธ๋จผํŠธ ํŠธ๋ฆฌ Segment Tree O(N*logN)
28 ํ”Œ๋กœ์ด๋“œ ์™€์ƒฌ Floyd Warshall O(V3)
29 ๋Š๋ฆฌ๊ฒŒ ๊ฐฑ์‹ ๋˜๋Š” ์„ธ๊ทธ๋จผํŠธ ํŠธ๋ฆฌ Segment Tree Lazy Propagation O(N*logN)
30 ์™ธํŒ์› ์ˆœํšŒ TSP O(2N)
31 ๋ฐฐ๋‚ญ ์•Œ๊ณ ๋ฆฌ์ฆ˜ KnapSack O(N*V)
32 ์ตœ์žฅ ๊ณตํ†ต ๋ฌธ์ž์—ด LCS (Longest Common Substring)
33 ์ตœ์žฅ ๊ณตํ†ต ๋ถ€๋ถ„ ๋ฌธ์ž์—ด LCS (Longest Common Subsequence)
34 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด LIS (Longest Increasing Subsequence) O(N*logN)
35 ์ตœ์žฅ ๊ณตํ†ต ์กฐ์ƒ LCA (Longest Common Ancestor) O(M*logN)
36 ํ•ด์‹œ Hash O(1)
37 ํŠธ๋ผ์ด Trie ์ƒ์„ฑ ์‹œ๊ฐ„๋ณต์žก๋„: O(M*L)
ํƒ์ƒ‰ ์‹œ๊ฐ„๋ณต์žก๋„: O(L)
(L: ์ œ์ผ ๊ธด ๋ฌธ์ž์—ด์˜ ๊ธธ์ด, M: ์ด ๋ฌธ์ž์—ด ์ˆ˜)
38 ๋จธ์ง€์†ŒํŠธ ํŠธ๋ฆฌ MergeSort Tree O(N*logN)
39 ๋ชจ์Šค ์•Œ๊ณ ๋ฆฌ์ฆ˜ + ์˜คํ”„๋ผ์ธ ์ฟผ๋ฆฌ mo's Algorithm + Offline Query O((N+Q)โˆšN * T(N))
(T(N): ๋ชจ์Šค ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ์ˆซ์ž๋ฅผ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜ ์ค„์ผ๋•Œ์˜ ์—ฐ์‚ฐ๋Ÿ‰)
40 ์˜ค์ผ๋ŸฌํšŒ๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜ Hierholzer's Algorithm O(E) (V: ์ •์ ์˜ ์ˆ˜, E: ๊ฐ„์„ ์˜ ์ˆ˜)
41 ์˜ค์ผ๋Ÿฌ๊ฒฝ๋กœ ํ…Œํฌ๋‹‰ Euler tour technic O(N) : ๊ฐ ๋…ธ๋“œ์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ถ™์—ฌ DFSํƒ์ƒ‰์„ ํ†ตํ•ด ์–ด๋””์„œ ๋“ค์–ด๊ฐ€๊ณ  ๋น ์ ธ๋‚˜์˜ค๋Š”์ง€๋ฅผ ๊ธฐ๋ก