2024. 1. 27. 21:16ใCS - Roadmap.sh/3. Common Algorithms
CS - 3. Common Algorithms - 3.5 Graph & 3.6 Tree
Graph Algorithms
๐กGraphs in data structures are non-linear data structures made up of a finite number of nodes or vertices and the edges that connect them. Graphs in data structures are used to address real-world problems in which it represents the problem area as a network like telephone networks, circuit networks, and social networks.
๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๊ทธ๋ํ๋ ํ์ ๋ ์์ ๋ ธ๋ ๋๋ ์ ์ ๊ณผ ์ด๋ฅผ ์ฐ๊ฒฐํ๋ ๊ฐ์ฅ์๋ฆฌ๋ก ๊ตฌ์ฑ๋ ๋น์ ํ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๋๋ค. ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๊ทธ๋ํ๋ ์ ํ๋ง, ํ๋ก๋ง, ์์ ๋คํธ์ํฌ์ ๊ฐ์ด ๋ฌธ์ ์์ญ์ ๋คํธ์ํฌ๋ก ํํํ๋ ์ค์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
Tree Algorithms
๐กA tree is non-linear and a hierarchical data structure consisting of a collection of nodes such that each node of the tree stores a value and a list of references to other nodes (the “children”).
Here is the list of common tree algorithms:
ํธ๋ฆฌ๋ ๋น์ ํ์ ์ด๋ฉฐ ๋ ธ๋ ๋ชจ์์ผ๋ก ๊ตฌ์ฑ๋ ๊ณ์ธต์ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ก, ํธ๋ฆฌ์ ๊ฐ ๋ ธ๋๊ฐ ๊ฐ๊ณผ ๋ค๋ฅธ ๋ ธ๋์ ๋ํ ์ฐธ์กฐ ๋ชฉ๋ก("์์")์ ์ ์ฅํฉ๋๋ค.
1.2 ๊ทธ๋ํ ์ 1.8 ํธ๋ฆฌ๋ฅผ ์๋ฃ๊ตฌ์กฐ์์ ๋ค๋ค์ต๋๋ค.
https://parkpakrsu.tistory.com/327
Data structures (with python) - 2. Graph - 2.1. Directed graph
Data structures (with python) - 2. Graph - 2.1. Directed graph ๐ก A directed graph is graph, i.e., a set of objects (called vertices or nodes) that are connected together, where all the edges are directed from one vertex to another. A directed graph is s
parkpakrsu.tistory.com
https://parkpakrsu.tistory.com/336
Data structures (with python) - 8.Tree - 8.1 Binary Tree
Data structures (with python) - 8.Tree - 8.1 Binary Tree Tree ๐ก A tree is non-linear and a hierarchical data structure consisting of a collection of nodes such that each node of the tree stores a value and a list of references to other nodes (the “chi
parkpakrsu.tistory.com
๋๋ค node์ edge๋ก ์ด๋ค์ง ๋ ธ๋๊ฐ์ ๊ด๊ฒ๋ฅผ ๋ํ๋ด๋ ์๋ฃ ๊ตฌ์กฐ์ ๋๋ค.
๊ทธ๋ํ์ ํธ๋ฆฌ๋ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ํํํ๋ ์๋ฃ๊ตฌ์กฐ์ด์ง๋ง, ๊ทธ ์ฑ๊ฒฉ๊ณผ ํน์ง์ ์์ด์ ๋ช ๊ฐ์ง ์ค์ํ ์ฐจ์ด์ ์ด ์์ต๋๋ค.
๊ทธ๋ํ(Graph): ๊ทธ๋ํ๋ ๋
ธ๋(Node)์ ์ด๋ค์ ์ฐ๊ฒฐํ๋ ๊ฐ์ (Edge)์ผ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.
๊ทธ๋ํ๋ ๋ ธ๋ ๊ฐ์ ๊ด๊ณ๋ฅผ ๋ํ๋ด๋ ๋ฐ ์ ์ฉํ๋ฉฐ, ๋ ธ๋์ ๊ฐ์ ์ ๊ฐ๊ฐ ๊ฐ์ฒด์ ๊ฐ์ฒด ๊ฐ์ ๊ด๊ณ๋ฅผ ๋ํ๋ ๋๋ค. ๊ทธ๋ํ๋ ๋ฐฉํฅ์ฑ์ด ์์ ์๋ (๋ฐฉํฅ ๊ทธ๋ํ), ์์ ์๋ (๋ฌด๋ฐฉํฅ ๊ทธ๋ํ) ์์ผ๋ฉฐ, ์ํ(์ฌ์ดํด) ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง ์๋ ์์ต๋๋ค. ์ฆ, ๊ทธ๋ํ์์๋ ์์ ๋ ธ๋์์ ์ถ๋ฐํด ๋ค์ ๊ฐ์ ๋ ธ๋๋ก ๋์์ฌ ์ ์์ต๋๋ค.
ํธ๋ฆฌ(Tree): ํธ๋ฆฌ๋ ๊ทธ๋ํ์ ํ ์ข
๋ฅ๋ก, ๋
ธ๋์ ๊ฐ์ ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ง๋ง, ๋ช ๊ฐ์ง ์ถ๊ฐ์ ์ธ ์ ์ฝ ์กฐ๊ฑด์ด ์์ต๋๋ค.
ํธ๋ฆฌ๋ ํ ๊ฐ์ ๋ฃจํธ ๋ ธ๋์์ ์์๋๋ฉฐ, ๋ฃจํธ ๋ ธ๋์์ ๋ค๋ฅธ ๋ชจ๋ ๋ ธ๋๋ก์ ๊ฒฝ๋ก๊ฐ ์ ์ผํฉ๋๋ค. ์ด๋ ํธ๋ฆฌ๊ฐ ์ํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง ์ ์์์ ์๋ฏธํ๋ฉฐ, ๋ฐ๋ผ์ ํธ๋ฆฌ์์๋ ์ด๋ค ๋ ธ๋์์ ์์ํด ๋ค์ ๊ฐ์ ๋ ธ๋๋ก ๋์์ค๋ ๊ฒฝ๋ก๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค. ๋ํ, ํธ๋ฆฌ๋ ๋ฐฉํฅ์ฑ์ด ์์ผ๋ฉฐ, ์ผ๋ฐ์ ์ผ๋ก ๋ฃจํธ ๋ ธ๋์์ ๋ค๋ฅธ ๋ ธ๋๋ก '๋ด๋ ค๊ฐ๋' ๋ฐฉํฅ์ฑ์ ๊ฐ์ง๋๋ค.
์ด๋ฌํ ์ฐจ์ด์ ๋ค๋ก ์ธํด, ๊ทธ๋ํ์ ํธ๋ฆฌ๋ ๊ฐ๊ฐ ๋ค๋ฅธ ์ข
๋ฅ์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ์ ํฉํฉ๋๋ค.
๊ทธ๋ํ๋ ๋คํธ์ํฌ ๊ตฌ์กฐ๋ฅผ ๋ชจ๋ธ๋งํ๊ฑฐ๋ ์ต๋จ ๊ฒฝ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ,
ํธ๋ฆฌ๋ ๊ณ์ธต์ ์ธ ๋ฐ์ดํฐ๋ฅผ ํํํ๊ฑฐ๋ ๊ฒ์ ์์ ์ ๋น ๋ฅด๊ฒ ์ํํ๋ ๋ฐ ์ ์ฉํฉ๋๋ค.
์์ผ๋ก ๋ค๋ค๋ณผ ๊ทธ๋ํ ์๊ณ ๋ฆฌ์ฆ๊ณผ ํธ๋ฆฌ ์๊ณ ๋ฆฌ์ฆ์ ์ข ๋ฅ๋ ์ด๋ ์ต๋๋ค.
Graph algorithm
- Breath First Search
- Depth First Search
- Bellman Ford's Algorithm
- Dijkstra's Algorithm
- A* Algorithm
Tree algorithm
- Pre-Order Traversal
- In-Order Traversal
- Post-Order Traversal
- Breadth First Search
- Depth First Search
ํ์คํ ํธ๋ฆฌ๋ ๊ฒ์์์ ์ ๋น ๋ฅด๊ฒ ์ํํ๋๋ฐ ์ ์ฉํ๋ค๊ณ ํ๋๋ฐ, ํธ๋ฆฌ ์๊ณ ๋ฆฌ์ฆ์ ๋ด์ฉ์ ์ํ์ ํ์์ด ์ฃผ๋ฅผ ์ด๋ฃน๋๋ค.
'CS - Roadmap.sh > 3. Common Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
3.5 Graph - 3.5.2 Depth First Search(DFS) (1) | 2024.01.29 |
---|---|
3.5 Graph - 3.5.1 Breadth First Search(BFS) (0) | 2024.01.28 |
3.4. Cache - 3.4.3 MFU Cache (0) | 2024.01.27 |
3.4. Cache - 3.4.2 LFU Cache (2) | 2024.01.26 |
3.4. Cache - 3.4.1 LRU Cache (2) | 2024.01.25 |