-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheap_lecture_data.js
More file actions
126 lines (120 loc) · 4.48 KB
/
Copy pathheap_lecture_data.js
File metadata and controls
126 lines (120 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
export const VISUAL_THEME = {
dark: {
edge: 'rgba(255,255,255,0.1)',
edgeHighlight: 'rgba(93,184,255,0.35)',
indexLabel: '#5e5c58',
node: {
normal: { f: '#1e1e21', s: 'rgba(255,255,255,0.12)', t: '#9b9891' },
root: { f: 'rgba(93,228,160,0.15)', s: '#5de4a0', t: '#5de4a0' },
target: { f: 'rgba(245,197,66,0.15)', s: '#f5c542', t: '#f5c542' },
compare: { f: 'rgba(93,184,255,0.12)', s: '#5db8ff', t: '#5db8ff' },
swap: { f: 'rgba(255,123,107,0.15)', s: '#ff7b6b', t: '#ff7b6b' },
done: { f: 'rgba(93,228,160,0.08)', s: '#2a7a52', t: '#5de4a0' },
},
},
light: {
edge: 'rgba(24,22,18,0.22)',
edgeHighlight: 'rgba(38,109,179,0.55)',
indexLabel: '#746d63',
node: {
normal: { f: '#f7f3ea', s: 'rgba(24,22,18,0.22)', t: '#5f5a51' },
root: { f: 'rgba(31,139,87,0.12)', s: '#1f8b57', t: '#176842' },
target: { f: 'rgba(181,123,0,0.14)', s: '#b57b00', t: '#8a5d00' },
compare: { f: 'rgba(38,109,179,0.12)', s: '#266db3', t: '#1f568d' },
swap: { f: 'rgba(198,90,77,0.12)', s: '#c65a4d', t: '#9e473d' },
done: { f: 'rgba(31,139,87,0.08)', s: '#2f7d58', t: '#176842' },
},
},
};
export const INSERT_POSITIONS = {
0: { x: 310, y: 38 },
1: { x: 175, y: 112 }, 2: { x: 445, y: 112 },
3: { x: 108, y: 186 }, 4: { x: 242, y: 186 }, 5: { x: 378, y: 186 }, 6: { x: 512, y: 186 },
7: { x: 63, y: 252 }, 8: { x: 141, y: 252 }, 9: { x: 209, y: 252 }, 10: { x: 277, y: 252 },
};
export const DEFAULT_POSITIONS = {
0: { x: 310, y: 35 },
1: { x: 175, y: 108 }, 2: { x: 445, y: 108 },
3: { x: 108, y: 181 }, 4: { x: 242, y: 181 }, 5: { x: 378, y: 181 }, 6: { x: 512, y: 181 },
7: { x: 63, y: 247 }, 8: { x: 141, y: 247 }, 9: { x: 209, y: 247 },
};
export const INSERT_SIMULATION = {
edges: [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[3,8],[4,9],[4,10]],
steps: [
{
vals: [2,5,8,12,9,20,15,25,30,18,3],
types: { 0: 'root', 10: 'target' },
log: '새 값 3을 맨 마지막 위치(인덱스 10)에 삽입합니다. 완전 이진 트리 구조 유지.',
},
{
vals: [2,5,8,12,3,20,15,25,30,18,9],
types: { 0: 'root', 4: 'swap', 10: 'swap' },
log: '3(인덱스 10) < 부모 9(인덱스 4) → 교환! Heapify Up: 위로 올라갑니다. 이동 1회.',
},
{
vals: [2,3,8,12,5,20,15,25,30,18,9],
types: { 0: 'root', 1: 'swap', 4: 'swap' },
log: '3(인덱스 4) < 부모 5(인덱스 1) → 교환! 계속 올라갑니다. 이동 2회.',
},
{
vals: [2,3,8,12,5,20,15,25,30,18,9],
types: { 0: 'root', 1: 'done' },
log: '3(인덱스 1)의 부모 2 ≤ 3 → 교환 불필요. 힙 조건 만족. 총 2회 교환 → O(log 11) ≈ 3.',
},
],
};
export const DELETE_SIMULATION = {
edges: [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[3,8]],
steps: [
{
vals: [18,5,8,12,9,20,15,25,30],
types: { 0: 'target' },
log: '루트 2를 꺼내고, 마지막 노드 18을 루트 자리로 이동. 이제 Heapify Down으로 제자리를 찾습니다.',
},
{
vals: [5,18,8,12,9,20,15,25,30],
types: { 0: 'swap', 1: 'swap', 2: 'compare' },
log: '18(루트) vs 왼쪽 5, 오른쪽 8. 더 작은 5와 비교 → 18 > 5 → 교환! 아래로 이동. 1회.',
},
{
vals: [5,9,8,12,18,20,15,25,30],
types: { 0: 'root', 1: 'done', 4: 'swap', 3: 'compare' },
log: '18(인덱스 4) vs 왼쪽 12, 오른쪽 없음. 18 > 12 → 교환! 리프 도달 → 종료. 총 2회 교환.',
},
{
vals: [5,9,8,12,18,20,15,25,30],
types: { 0: 'root' },
log: '삭제 완료. 새 최솟값 5가 루트. 힙 속성 완전 복구.',
},
],
};
export const MAP_SIMULATION = {
values: [2,5,8,12,9,20,15,25,30,18],
edges: [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[3,8],[4,9]],
};
export const PROBLEM_SIMULATION = [
{
heap: [1,2,3,9,10,12],
hi: [],
cnt: 0,
log: '초기 상태: [1,2,3,9,10,12]. 루트(최솟값) = 1. K=7보다 작으므로 섞기 시작.',
},
{
heap: [3,9,5,10,12],
hi: [0,2],
cnt: 1,
log: '[1회] poll(1) + poll(2) → 1 + 2×2 = 5 삽입, Heapify. 힙 = [3,9,5,10,12]. 루트 3 < 7 → 계속.',
},
{
heap: [9,10,13,12],
hi: [0],
cnt: 2,
log: '[2회] poll(3) + poll(5) → 3 + 5×2 = 13 삽입, Heapify. 힙 = [9,10,13,12]. 루트 9 ≥ 7 → 종료!',
},
{
heap: [9,10,13,12],
hi: [0],
cnt: 2,
log: '완료. 모든 값이 K(7) 이상. 정답: 2회. 전체 과정 O(N log N).',
},
];