9148c358d0
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 폴더 제거.
5.5 KiB
5.5 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-graph-theory | Graph Theory | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
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.
매 응용
- Routing / map — 매 OSRM, Valhalla, Google Maps.
- Dependency resolution — npm, cargo, Bazel.
- GNN — 매 fraud detection, drug discovery, recommendation (Pinterest PinSage).
- Knowledge graph — 매 RAG / LLM grounding.
💻 패턴
Adjacency list (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
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)
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)
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)
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)
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)
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 응용 정리 |