힙 (Heaps)

Henry Lee·2020년 12월 3일
0
post-thumbnail

이진 트리(Binary Tree)의 한 종류.

max heap과 min heap.
python의 heapq는 min heap 구현.

삽입/삭제 연산 구현
마지막 자리에 new node를 insert해서 parent와 비교 / 위치 조정.
root를 remove한 후, 마지막 자리의 node를 root에 배치 child와 비교 / 위치 조정.
(이 경우, child가 둘 이면 비교 후 이동.)

응용

  1. 우선순위큐 (priority queue)
  2. 힙 정렬 (heap sort)
profile
Today I Learned. AI Engineer.

0개의 댓글