Python에서 heapq 모듈의 heappush()와 heappop()의 특징은?
보통 freeCodeCamp해설
heapq 모듈은 리스트를 이진 최소 힙으로 관리합니다. heappush(h, 3)으로 삽입하고 heappop(h)으로 가장 작은 원소를 꺼냅니다. heapq.nlargest(), heapq.nsmallest()로 상위/하위 n개를 효율적으로 구할 수 있어 우선순위 큐 구현에 사용됩니다.
heapq 모듈은 리스트를 이진 최소 힙으로 관리합니다. heappush(h, 3)으로 삽입하고 heappop(h)으로 가장 작은 원소를 꺼냅니다. heapq.nlargest(), heapq.nsmallest()로 상위/하위 n개를 효율적으로 구할 수 있어 우선순위 큐 구현에 사용됩니다.