그래프와 트리
도입됨
5:38
이산 수학
Discrete mathematics is the mathematics of objects you can list: statements, sets, graphs and arrangements. The first three units build the proof engine…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| graph/ɡræf/ | 그래프 |
| edge/edʒ/ | 변 |
| degree/dɪˈɡriː/ | 차수 |
| directed/daɪˈrektɪd/ | 유향 |
| vertex/ˈvɜːteks/ | 정점 |
| adjacency matrix/əˈdʒeɪsənsi ˈmeɪtrɪks/ | 인접 행렬 |
| adjacency list/əˈdʒeɪsənsi lɪst/ | 인접 목록 |
| sparse/spɑːs/ | 희소 |
| handshake lemma/ˈhændʃeɪk ˈlemə/ | 손잡이 정리 |
| tree/triː/ | 나무 구조 |
| acyclic/əˈkaɪklɪk/ | 무순환 |
| leaf/liːf/ | 잎 |
| breadth-first search/bredθ fɜːst sɜːtʃ/ | 너비 우선 탐색 |
| depth-first search/depθ fɜːst sɜːtʃ/ | 깊이 우선 탐색 |
Friends, flights and build steps
- A social network, an airline map and the order in which code modules must compile look nothing alike. Each one is a set of things joined by links.
- That shared shape is a graph 图. Learn it once and the same tools count, search and check all three.
Vertices, edges and degree
- A graph 图 $G = (V, E)$ has vertices 顶点 $V$ and edges 边 $E$ joining pairs of them. Edges can be directed 有向 (one-way, like build order) or undirected (like friendship).
- The degree 度 of a vertex is the number of edges touching it. An isolated vertex has degree 0 and still counts as a vertex.
각 시스템을 모델링하는 그래프의 종류에 매칭하십시오.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
우정 관계는 양방향입니다; 빌드 순서는 단방향이며 루프할 수 없으며; 거리는 가중치이며; 링크는 뒤로 향할 수 있습니다.
Two ways to store a graph
- An adjacency matrix 邻接矩阵 is an $n \times n$ grid of 0s and 1s. It takes $n^2$ space but answers "is there an edge from $u$ to $v$?" in $O(1)$.
- An adjacency list 邻接表 stores each vertex's neighbours. It takes $O(|V| + |E|)$ space, so it suits sparse 稀疏 graphs with few edges per vertex.

한 도로 지도에는 백만 개의 교차로가 있으며, 각 교차로는 약 네 곳과 연결되어 있습니다. 가장 좋은 저장 방식은 —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
행렬은 10¹²개의 셀이 필요하며, 거의 대부분이 0입니다. 리스트는 존재하는 약 4백만 개의 엣지만 저장합니다.
The handshake lemma
- Each edge adds 1 to the degree of each of its two ends, so $\sum_v \deg(v) = 2|E|$. This is the handshake lemma 握手引理. In the figure, $3 + 2 + 2 + 2 + 3 = 12 = 2 \times 6$.
- Corollary: the number of odd-degree vertices is always even. Seven people cannot each shake hands with exactly three others, because $7 \times 3 = 21$ is odd.
그래프에 9개의 엣지가 있습니다. 모든 정점의 차수의 합은?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
각 지는 2를 더하므로, $2 \times 9 = 18$입니다.
그래프는 정확히 세 개의 홀수 차수를 가진 정점을 가질 수 있습니다.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
차수의 합은 짝수이므로, 홀수 차수는 짝수 개로 나타납니다.
Trees: connected, no cycles
- A tree 树 is connected (one piece) and acyclic 无环 (no cycles). Every tree with $|V|$ vertices has exactly $|E| = |V| - 1$ edges.
- A leaf 叶子 has degree 1. Combine the two facts with the handshake lemma to answer most tree questions.
A tree has 12 vertices, 5 of them leaves. Edges: $12 - 1 = 11$, so the degree sum is $2 \times 11 = 22$. The leaves give 5, so the other 7 vertices carry $22 - 5 = 17$.
나무에 30개의 정점이 있습니다. 엣지의 개수는?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
모든 나무는 $|E| = |V| - 1 = 29$를 가집니다.
Two ways to search
- Breadth-first search 广度优先搜索 (BFS) uses a queue and visits level by level. In an unweighted graph it finds shortest paths, counted in edges.
- Depth-first search 深度优先搜索 (DFS) uses a stack or recursion and goes as deep as it can before backing up. It finds connected pieces and detects cycles.
BFS에 대한 다음 중 참인 진술은 무엇입니까? 모두 선택하십시오.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
BFS는 간선의 개수를 세므로 모든 간선의 비용이 동일할 때만 최단 경로를 제공합니다.
Marks that slip away
- Connected is not complete. Connected means one piece; complete means every pair is joined.
- BFS on weighted graphs. BFS counts edges 边, not weights; a weighted shortest path needs another method.
- Ignoring degree-0 vertices. They still count in $|V|$.
You've got it
- $G = (V, E)$, stored one of two ways:
| Adjacency matrix 邻接矩阵 | Adjacency list | |
|---|---|---|
| Space | $n^2$ | $O(\lvert V\rvert + \lvert E\rvert)$ |
| "Edge $u \to v$?" | $O(1)$ | scan $u$'s list |
| Best for | dense graphs | sparse graphs |
- $\sum \deg = 2|E|$, so the number of odd-degree vertices is even.
- Tree: connected and acyclic, $|E| = |V| - 1$.
| BFS | DFS | |
|---|---|---|
| Uses | a queue | a stack or recursion |
| Visits | level by level | as deep as it can |
| Finds | shortest paths in edges | pieces and cycles |
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.