일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- BFS
- Queue
- 코딩
- join
- programmers
- 데이터분석
- counter
- coding test
- 시간복잡도
- lv4
- Level2
- level4
- sql
- time complexity
- 완전탐색
- collections
- 코테
- import re
- coding
- 조합
- python
- CodingTest
- 프로그래머스
- 파이썬
- lambda
- Stack
- 연습문제
- 코딩테스트
- itertools
- mysql
- Today
- Total
목록Priority Queue (1)
ror_coding
[Python] Heap (Priority Queue)
heapq 는 "우선순위 큐(Priority Queue)"를 구현하는 데 유용함. 우선순위 큐 ) 항목의 우선순위에 따라 처리되는 데이터 구조.따라서 가장 작은(또는 가장 큰) 항목을 우선적으로 처리하는데 사용됨.ex) 작업 스케줄링, 다익스트라 알고리즘(Dijkstra's algorithm) 등. import heapqheapq.heapify(l1) # => 자동 정렬된 list(heap)가 됨. # O(n)# 1. 삽입/추출heapq.heappush(lst, 0) # O(log n)= heapq.heappop(lst) # O(log n)# 2. 삽입+추출= heapq.heappushpop(lst, 0) # O(log n) # 삽입 후, 바로 최솟값 추출.= heapq.heapreplace(lst, i..
Algorithm/Python
2024. 12. 8. 15:36