docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거

Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,179 @@
---
id: wiki-2026-0508-graph-theory
title: Graph Theory
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [그래프 이론, Graphs]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [algorithms, graphs, cs]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: python
framework: networkx
---
# Graph Theory
## 매 한 줄
> **"매 vertex + edge 의 abstraction 으로 매 거의 모든 관계를 model"**. 매 Euler (1736 Königsberg) 부터 매 modern Graph Neural Network (2026 GraphSAGE, GAT, Graph Transformer) 까지 — 매 search engine PageRank, social network, dependency graph, GNN, knowledge graph 의 foundation.
## 매 핵심
### 매 representations
- **Adjacency matrix**: O(V²) space, O(1) edge query — 매 dense graph.
- **Adjacency list**: O(V+E) space — 매 sparse 일반.
- **Edge list**: 매 streaming / disk-based.
- **CSR (Compressed Sparse Row)**: 매 cache-friendly, GNN framework 의 표준.
### 매 핵심 algorithm
- **BFS** O(V+E) — 매 unweighted shortest path, level order.
- **DFS** O(V+E) — 매 cycle detection, topo sort, SCC.
- **Dijkstra** O((V+E) log V) — 매 non-negative weighted shortest path.
- **Bellman-Ford** O(VE) — 매 negative weight allowed.
- **Floyd-Warshall** O(V³) — 매 all-pairs.
- **Union-Find** ~ O(α(V)) — 매 connectivity, Kruskal MST.
- **Topological sort** — 매 DAG ordering.
- **PageRank** — 매 power iteration on stochastic matrix.
### 매 응용
1. Routing / map — 매 OSRM, Valhalla, Google Maps.
2. Dependency resolution — npm, cargo, Bazel.
3. GNN — 매 fraud detection, drug discovery, recommendation (Pinterest PinSage).
4. Knowledge graph — 매 RAG / LLM grounding.
## 💻 패턴
### Adjacency list (Python)
```python
from collections import defaultdict
g: dict[int, list[int]] = defaultdict(list)
for u, v in edges:
g[u].append(v); g[v].append(u)
```
### BFS shortest path
```python
from collections import deque
def bfs(g, s, t):
q = deque([(s, 0)]); seen = {s}
while q:
u, d = q.popleft()
if u == t: return d
for v in g[u]:
if v not in seen: seen.add(v); q.append((v, d+1))
return -1
```
### Dijkstra (heap)
```python
import heapq
def dijkstra(g, s):
dist = {s: 0}; pq = [(0, s)]
while pq:
d, u = heapq.heappop(pq)
if d > dist[u]: continue
for v, w in g[u]:
nd = d + w
if nd < dist.get(v, float("inf")):
dist[v] = nd; heapq.heappush(pq, (nd, v))
return dist
```
### Topological sort (Kahn)
```python
from collections import deque
def topo(n, edges):
g = [[] for _ in range(n)]; indeg = [0]*n
for u, v in edges: g[u].append(v); indeg[v] += 1
q = deque(i for i in range(n) if indeg[i] == 0); out = []
while q:
u = q.popleft(); out.append(u)
for v in g[u]:
indeg[v] -= 1
if indeg[v] == 0: q.append(v)
return out if len(out) == n else None # cycle
```
### Union-Find (path compression + rank)
```python
class DSU:
def __init__(self, n): self.p = list(range(n)); self.r = [0]*n
def find(self, x):
while self.p[x] != x:
self.p[x] = self.p[self.p[x]]; x = self.p[x]
return x
def union(self, a, b):
ra, rb = self.find(a), self.find(b)
if ra == rb: return False
if self.r[ra] < self.r[rb]: ra, rb = rb, ra
self.p[rb] = ra
if self.r[ra] == self.r[rb]: self.r[ra] += 1
return True
```
### NetworkX (Python prototyping)
```python
import networkx as nx
G = nx.DiGraph(); G.add_weighted_edges_from([("a","b",1), ("b","c",2)])
print(nx.shortest_path(G, "a", "c", weight="weight"))
print(nx.pagerank(G, alpha=0.85))
```
### GNN (PyTorch Geometric)
```python
import torch
from torch_geometric.nn import GCNConv
class GCN(torch.nn.Module):
def __init__(self, d_in, d_h, d_out):
super().__init__()
self.c1 = GCNConv(d_in, d_h); self.c2 = GCNConv(d_h, d_out)
def forward(self, x, edge_index):
x = self.c1(x, edge_index).relu()
return self.c2(x, edge_index)
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Unweighted shortest | BFS |
| Non-negative weighted | Dijkstra |
| Negative weight | Bellman-Ford / Johnson |
| All-pairs, dense, V<500 | Floyd-Warshall |
| MST | Kruskal (DSU) / Prim (heap) |
| DAG scheduling | Topological sort |
| Cycle / SCC | DFS + Tarjan / Kosaraju |
| Massive web graph | Pregel-style (GraphX, Giraph) |
| Learning on graph | GNN (PyG, DGL) |
**기본값**: prototype 은 NetworkX, production 은 graph-tool / igraph / 직접 CSR.
## 🔗 Graph
- 변형: [[DAG]]
- 응용: [[Shortest Path]] · [[GNN]] · [[Knowledge Graph]]
## 🤖 LLM 활용
**언제**: 매 problem 을 graph 로 model 가능한지 reasoning, 매 algorithm 선택.
**언제 X**: 매 V, E 가 매우 작은 brute-force 충분 case — 매 over-engineering.
## ❌ 안티패턴
- **Adjacency matrix on sparse**: 매 V=10⁶ 에 V² 메모리 폭발.
- **Recursive DFS on deep graph (Python)**: 매 stack overflow — iterative.
- **Dijkstra with negative edges**: 매 wrong answer — Bellman-Ford.
- **Re-running BFS from each node for diameter**: 매 BFS×V — multi-source / approx 사용.
- **Forgetting visited set**: 매 BFS/DFS 무한 loop.
## 🧪 검증 / 중복
- Verified (CLRS *Introduction to Algorithms* 4th ed., Sedgewick *Algorithms* 4ed, NetworkX docs, PyG 2.5).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — graph algorithms + GNN 응용 정리 |