목록힙 (2)
넘치게 채우기
https://leetcode.com/problems/kth-largest-element-in-a-stream/description/ Kth Largest Element in a Stream - LeetCode Can you solve this real interview question? Kth Largest Element in a Stream - Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class: leetcode.com 문제 유형 : 우선..

힙 힙(Heap)은 다음과 같은 특성을 가지고 있다: 1. 완전 이진 트리이다. 2. (부모 노드의 index) = (자식 노드의 index) // 2 3. (왼쪽 자식의 index) = (부모 노드의 index) * 2 4. (오른쪽 자식의 index) = (부모 노드의 index) *2 +1 5. 루트의 index는 1이다. (구현의 편의상 1부터 시작한다.) 힙은 이러한 특성때문에 보통 배열로 많이 구현한다. 힙의 삽입과 삭제는 O(log N)이 걸리고, 탐색에는 O(N)이 걸린다. 힙은 두 가지의 종류가 있다. 최대 힙과 최소 힙이다. 최대 힙(max heap)은 부모 노드의 key값이 자식 노드의 key 값보다 큰 힙이고, 최소 힙(min heap)은 부모 노드의 key값이 자식 노드의 key ..