44,000원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결비전공자의 전공자 따라잡기 - 자료구조(with JavaScript)
let current = this.head 질문 있습니다!
this.head 대신 let current = this.head 처럼 current변수에 할당하여 사용하는 이유가 무엇일까요?ㅠ변수에 할당하여 사용하지 않았을 때 값을 보니 값이 다르게 나와 문의드립니다. li.add(3)이 실행될때 첫번째 노드가 사라짐 정상출력
- 미해결비전공자의 전공자 따라잡기 - 자료구조(with JavaScript)
퀴즈 답안
퀴즈 답안지는 따로 제공되지 않나요?
- 미해결비전공자의 전공자 따라잡기 - 자료구조(with JavaScript)
최소힙의 결과값과 최대힙->최소힙 결과값이 다른게 맞나요?
최소 힙 insert#reheapUp(index) { // index 0은 root if (index > 0) { // 부모 노드가 root가 아니면 계속 비교 const parentIndex = Math.floor((index - 1) / 2); if (this.arr[index] < this.arr[parentIndex]) { // 값 바꾸기 const temp = this.arr[index]; this.arr[index] = this.arr[parentIndex]; this.arr[parentIndex] = temp; this.#reheapUp(parentIndex); } } } // O (log n) insert(value) { this.arr.push(value); this.#reheapUp(this.arr.length - 1); }const heap = new MinHeap(); // insert는 큰 값부터 넣고, root가 8이 되는지 확인 heap.insert(78); heap.insert(56); heap.insert(45); heap.insert(32); heap.insert(23); heap.insert(19); heap.insert(8); // [8, 32, 19, 78, 45, 56, 23] heap; 최대 힙 insert#reheapUp(index) { // index 0은 root if (index > 0) { // 부모 노드가 root가 아니면 계속 비교 const parentIndex = Math.floor((index - 1) / 2); if (this.arr[index] > this.arr[parentIndex]) { // 값 바꾸기 const temp = this.arr[index]; this.arr[index] = this.arr[parentIndex]; this.arr[parentIndex] = temp; this.#reheapUp(parentIndex); } } } // O (log n) insert(value) { this.arr.push(value); this.#reheapUp(this.arr.length - 1); }const heap = new MaxHeap(); // insert는 작은 값부터 넣고, root가 78이 되는지 확인 heap.insert(8); heap.insert(19); heap.insert(23); heap.insert(32); heap.insert(45); heap.insert(56); heap.insert(78); // [78, 32, 56, 8, 23, 19, 45] heap; 최대 힙 -> 최소 힙// 최소 힙 유지 함수 #heapifyMin(index) { // 수정, 삭제 const leftIndex = index * 2 + 1; const rightIndex = index * 2 + 2; const smallerIndex = (this.arr[leftIndex] || 0) < (this.arr[rightIndex] || 0) ? leftIndex : rightIndex; if (this.arr[index] > this.arr[smallerIndex]) { // 값 바꾸기 const temp = this.arr[index]; this.arr[index] = this.arr[smallerIndex]; this.arr[smallerIndex] = temp; // 재귀적으로 최소 힙 유지 this.#heapifyMin(smallerIndex); } } toMinHeap() { // O(1/2n) for (let i = Math.floor(this.arr.length / 2 - 1); i >= 0; i--) { this.#heapifyMin(i); } }const heap = new MaxHeap(); // insert는 작은 값부터 넣고, root가 78이 되는지 확인 heap.insert(8); heap.insert(19); heap.insert(23); heap.insert(32); heap.insert(45); heap.insert(56); heap.insert(78); // [78, 32, 56, 8, 23, 19, 45] heap.toMinHeap(); // [8, 23, 19, 32, 78, 56, 45] heap; // 최소 힙 insert 결과 값 [8, 32, 19, 78, 45, 56, 23] // 최대 힙 insert 결과 값 [78, 32, 56, 8, 23, 19, 45] // 최대 힙 -> 최소 힙 결과 값 [8, 23, 19, 32, 78, 56, 45] 최소힙 insert 결과 값과 최대 힙 -> 최소 힙 결과 값은 서로 다른데 최소 힙의 조건은 아래가 크고, 위가 작다. 라고 하셨으니 결과 값은 달라도 최소 힙의 조건이 맞으니 최대 힙 -> 최소 힙 변환 코드가 맞는걸까요?
- 미해결비전공자의 전공자 따라잡기 - 자료구조(with JavaScript)
1주차 숙제에 대한 해답 코드는 따로 제공되지 않나요??
1주차 마지막 강의인 숙제에 대한 코드를 따로 제공되지 않나요?