Heap
Heap이란? 우선순위 큐를 위하여 고안된 자료구조이다. 완전 이진 트리의 일종이며 반 정렬 상태이다. 삽입과 삭제의 시간 복잡도가 O(logN)이다. 종류로는 Max Heap과 Min Heap이 있다. 아래는 JavaScript버전으로 Heap을 구현하였으며 하나는 Class버전으로 하나는 Array버전으로 작성하였다. Class버전은 Max Heap, Array버전은 Min Heap이다. (1)Class 버전 class maxheap{ constructor() { this.heap = []; } swap(a,b){ [this.heap[a],this.heap[b]] = [this.heap[b],this.heap[a]]; } size(){ return this.heap.length; } add(value..
2022.12.16