In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation. Algorithms are always unambiguous and are used as specifications for performing calculations, data processing, automated reasoning, and other tasks. - Wikipedia.
์ํ๊ณผ ์ปดํจํฐ ๊ณผํ์์, ์๊ณ ๋ฆฌ์ฆ์ ์ผ๋ฐ์ ์ผ๋ก ์ด๋ค ์งํฉ์ ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํ๊ฑฐ๋ ๊ณ์ฐ์ ์ํํ๊ธฐ ์ํด, ์ ์ ์๋ ํ ์ ํ์์์ด์, ์ปดํจํฐ๊ฐ ์คํํ ์ ์๋ ์ง์์ฌํญ๋ค ์ ๋๋ค. ์๊ณ ๋ฆฌ์ฆ์ ํญ์ ๋ชจํธํ์ง ์๊ณ , ๊ณ์ฐ์ด๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ, ์๋ ์ถ๋ก ๋ฑ๋ฑ ์ฌ๋ฌ๊ณณ์์์ ๋ช ์ธ๋ก ์ฌ์ฉ๋ฉ๋๋ค.
-
DFS - Recursion manner - O(V+E)
-
BFS - Using Queue - O(V+E)
-
Binary Search - Iterative manner - O(logn)
-
Binary Search - Recursive manner - O(logn)
-
Permutation - O(n!) ์์ด
-
Power Set Problem - O(2^n) ๋ชจ๋ ์กฐํฉ ๋์ด
-
N Queen Problem - N x N ๊ฒฉ์ํ์ N๊ฐ์ ํธ์ด ์๋ก ๊ณต๊ฒฉํ์ง ์์ผ๋ฉด์ ๋์์ง๊ฒ ํ๋ ๋ฒ ๊ตฌํ๊ธฐ
-
Rat In A Maze Problem - ๋ฏธ๋ก์ฐพ๊ธฐ ๋ฌธ์
-
Sudoku - ์ค๋์ฟ , ์ซ์ ํผ์ฆ ๋ฌธ์
-
Sum Of Subset - ์งํฉ์์์ ์์๋ค์ ์กฐํฉํด์ ํน์ ๊ฐ์ ๋ง๋ค ์ ์๋์ง? O(2^n)
-
Pre Order, In Order, Post Order - ์ ์ ์ํ, ์ค์ ์ํ, ํ์ ์ํ | ๊ธฐ๋ณธ์ ์ธ ํธ๋ฆฌ์ ์ํ ๋ฐฉ๋ฒ
-
Center of a Binary Tree - ํธ๋ฆฌ์ ์ค์ฌ(1๊ฐ ๋๋ ์ต๋ 2๊ฐ๊ฐ ๋ ์ ์๋ค.)
-
Height of a Binary Tree - ํธ๋ฆฌ์ ๋์ด(๋ฃจํธ๋ ธ๋๋ก ๋ถํฐ ๊ฐ์ฅ ๊น์ ์ ๋ ธ๋๋ก์ ๊ฒฝ๋ก์์์ ๋ ธ๋ ๊ฐ์)
-
Diameter of a Binary Tree - ํธ๋ฆฌ์ ์ง๋ฆ(ํธ๋ฆฌ์์ ๊ฐ์ฅ ๊ธด ๊ฒฝ๋ก์ ๋ ธ๋ ๊ฐ์)
-
Sum of Nodes - ํธ๋ฆฌ์์์ ๋ ธ๋๋ค์ ํฉ
-
Sum of Leaf Nodes - ์ ๋ ธ๋๋ค์ ํฉ
-
Dijkstra Algorithm - Priority Queue(Binary Heap) - Binary Heap ์ ์ฉ O(E(logV)
-
Dijkstra Algorithm - Min Indexed Heap - Indexed Priority Queue ์ ์ฉ O(V(logV)
-
Floyd Washall Algorithm - All Pair Shortest Path - ๋ชจ๋ ์ ์ต๋จ๊ฒฝ๋ก O(v^3)
-
SPFA - Shortest Path Faster Algorithm - O(E) on Average. Not proved. ํด๋น ์๊ณ ๋ฆฌ์ฆ ๋ธ๋ก๊ทธ ๊ธ ๋ณด๊ธฐ
-
Bellman Ford - Adjacency List - O(VE)
-
Bellman Ford - Edge List - O(VE)
-
Shortest Path On DAG Using TopSort - ์์์ ๋ ฌ ์ ์ฉ ํ ์์์์์ ๋ฐ๋ผ ๋ณ ๊ฒฝ๊ฐ ์ฐ์ฐ ์ํ O(V+E)
-
Shortest Path On A Graph Using BFS - ๊ทธ๋ํ์์ ๋ชจ๋ Edge์ ๊ฐ์ค์น๊ฐ ๊ฐ์ ์ํฉ์์์ ์ต๋จ๊ฒฝ๋ก O(V+E)
-
Quick sort - ๋น ๋ฅธ์ ๋ ฌ, Worst case: O(n^2), Average case: O(nlogn) where n is the number of item in an array
-
Merge sort - ๋ณํฉ์ ๋ ฌ O(nlogn), Worst case: O(nlogn) where n is the number of item in an array
-
Counting sort - ์นด์ดํ ์ํธ, ๊ณ์์ ๋ ฌ, O(kn) where k is upper bound number, n is the # of items in an array
-
Selection sort - ์ ํ์ ๋ ฌ Worst case: O(n^2)
-
Bubble sort - ๋ฒ๋ธ์ํธ Worst case: O(n^2)
-
Insertion sort - ์ฝ์ ์ ๋ ฌ Worst case: O(n^2)
-
Heap sort - ํ ์ ๋ ฌ Worst case: O(nlogn)
-
Radix sort - ๊ธฐ์ ์ ๋ ฌ, Time Complexity: O(nw) n = ์ ๋ ฌ๋ ํค์ ๊ฐ์, w = ์ ๋ ฌ๋ ํค ์ค์์ ๊ฐ์ฅ ํฐ ์๋ฆฟ์
-
Bucket sort - ๋ฒํท ์ํธ
-
Topological Sort - Using In Degree - Using In Degree, O(V+E)
-
Topological Sort - Using DFS - Using DFS, O(V+E)
-
Fibonacci - Bottom up Manner - n๋ฒ์งธ ํผ๋ณด๋์น ์์ด ๊ตฌํ๊ธฐ(๋ฐ๋ณต์ ๋ฐฉ๋ฒ), Iterative
-
Fibonacci - Top Down Manner - n๋ฒ์งธ ํผ๋ณด๋์น ์์ด ๊ตฌํ๊ธฐ(์ฌ๊ท์ ๋ฐฉ๋ฒ), Recursive + Memoization
-
Maximum Sum Sub array(Kadene's Algorithm) - ๋ฐฐ์ด์์์ ์ฐ์๋ ๋ถ๋ถ๋ฐฐ์ด์ ์ต๋ ํฉ, O(n)
-
Coin Change Problem 1 - ์ฃผ์ด์ง ์ข ๋ฅ์ ์ฝ์ธ์ผ๋ก ํน์ ๊ธ์ก์ ๋ง๋๋๋ฐ ๋๋ ๊ฐ๋ฅํ ์ต์์ ๋์ ์ (๋์ ์ ๊ฐ์๋ ๋ฌดํ)
-
Coin Change Problem 2 - ์ฃผ์ด์ง ์ข ๋ฅ์ ์ฝ์ธ์ผ๋ก ํน์ ๊ธ์ก์ ๋ง๋ค ์ ์๋ ๊ฒฝ์ฐ์ ์(์กฐํฉ์ ์) (๋์ ์ ๊ฐ์๋ ๋ฌดํ)
-
0 1 Knapsack - ๋ฌผ๊ฑด์ ์๋์ด ์ต๋ 1๊ฐ์ธ ๋ฐฐ๋ญ ๋ฌธ์
-
Unbounded Knapsack - ๋ฌผ๊ฑด์ ์๋์ด ์ ํ ์๋ ๋ฐฐ๋ญ ๋ฌธ์
-
LCS(Longest Common Subsequence) - ์ต์ฅ ๊ณตํต ๋ถ๋ถ ์์(Compare with 3 Strings), Bottom Up Manner O(n^3)
-
LCS(Longest Common Substring) - ์ต์ฅ ๊ณตํต ๋ถ๋ถ ๋ฌธ์์ด(Compare with 2 Strings), Bottom Up Manner O(n^2)
-
LIS(Longest Increasing Subsequence) - ์ต์ฅ ์ฆ๊ฐ ๋ถ๋ถ์์, Bottom Up Manner O(n^2)
-
Maximum Sub Square Matrix of 1 - 1๋ก ์ด๋ฃจ์ด์ง ๊ฐ์ฅ ํฐ ์ ์ฌ๊ฐํ ๋ถ๋ถ ํ๋ ฌ ๊ตฌํ๊ธฐ
-
Stair Case Problem N๋ฒ ๊ณ๋จ ๊น์ง ์ฌ๋ผ๊ฐ๋ ๋ฐฉ๋ฒ์ ์
-
Tiling Dominoes - ํ์ผ๋ง ๋ฌธ์ , e.g 2 x N or 3 x N and so on
-
Edit Distance - ํธ์ง๊ฑฐ๋ฆฌ
-
Longest Palindrome Subsequence - ์ต์ฅ ํฐ๋ฆฐ๋๋กฌ ๋ถ๋ถ์์
-
Josephus Problem - ์กฐ์ธํผ์ค ๋ฌธ์
-
Mountain Scenes - Problem Link : Click Here
-
Magical Cows - Problem Link : Click Here
-
Tiling Dominos - Problem Link : Click Here
- Sieve Of Eratosthenes - ์๋ผํ ์คํ ๋ค์ค์ ์ฒด
-
Permutation - ์์ด nPr, ์์ํ
-
Permutation Using Swap - ์์ด nPn, ๋น์์ํ
-
Combination - ์กฐํฉ nCr
-
Combination With Repetition - ์ค๋ณต ์กฐํฉ
-
Kruskal's Algorithm - ๊ฐ๋ฅํ ๊ฐ์ค์น๊ฐ ๊ฐ์ฅ ์์ ๊ฐ์ ์ผ๋ก ์์ํด N-1๊ฐ์ ๊ฐ์ ์ ์ ํํ๋ Greedy Algorithm
-
Prim's Algorithm
-
Ford-Fulkerson method - ์ต๋์ ๋ ์๊ณ ๋ฆฌ์ฆ
-
Edmonds Karp Algorithm - ์ต๋์ ๋ ์๊ณ ๋ฆฌ์ฆ, Ford Fulkerson method์์์ ํ์๋ฐฉ๋ฒ์ BFS๋ก ์ ์ฉ
-
Min Cost Max Flow - ์ต์๋น์ฉ ์ต๋์ ๋ ์๊ณ ๋ฆฌ์ฆ, ์ต์๋น์ฉ์๋ SPFA Algorithm, ์ต๋๋น์ฉ์๋ Edmonds Karp Algorithm ์ ์ฉ
- Bipartite Matching - DFS Manner
-
Tarjan's Algorithm - O(V+E)
-
Kosaraju's Algorithm - O(V+E)
-
Cut Edge - O(V+E)
-
Articulation Point - O(V+E)
-
Cycle Detection in a Directed Graph - ๋ฐฉํฅ ๊ทธ๋ํ์์์ ์ฌ์ดํด ํ์ง, DFS ์ฌ์ฉ - O(V+E)
-
Cycle Detection in an UnDirected Graph - ๋น๋ฐฉํฅ ๊ทธ๋ํ์์์ ์ฌ์ดํด ํ์ง, ์ ๋์จ ํ์ธ๋ ์ฌ์ฉ - O(V+E)
-
LCA - Euler Tour + Sparse Table(RMQ) Euler Tour = O(n), Construction of Sparse Table = O(nlogn), LCA Query = O(1)
-
LCA - Naive Approach LCA Query = O(n)
-
KMP Pattern Matching Algorithm - KMP(Knuth, Morris, Pratt) ํจํด ๋งค์นญ ์๊ณ ๋ฆฌ์ฆ, O(n+m) where n is pattern matching and m is LPS construction (LPS : Longest Proper Prefix which is also Suffix)
-
Boyer Moore Algorithm - Using Bad Character Rule
-
Rabin Karp Algorithm
- Count Inversions In An Array - ์ธ๋ฑ์ค ์์น๊ฐ i < j ์ด๋ฉด์ A[i] > A[j]์ธ ์์๋ค์ ์ญ์ ๊ด๊ณ๋ผ๊ณ ํ๋ค. ์ญ์ ๊ด๊ณ์ ์์๋ค์ด ํด๋น ๋ฐฐ์ด์์ ๋ช๊ฐ๋ ์๋์ง ์ฐพ๋ ์๊ณ ๋ฆฌ์ฆ. ๋จธ์ง์ํธ๋ฅผ ์ด์ฉํ๋ค. O(nlogn), Naive Approach : O(n^2)
In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. - Wikipedia
- [Implementation]
-
Segment Tree - Range Sum Query - Construction : O(n), Update: O(logn), Min Query : O(logn)
-
Segment Tree - Range Minimum Query - Construction : O(n), Update: O(logn), Min Query : O(logn)
- Fenwick Tree - Range Sum Query - Construction : O(n), Update: O(logn), Sum Query : O(logn)
- Sparse Table - Range Minimum Query - Construction : O(nlogn), Min Query : O(1)