Hướng dẫn python heapq nlargest dictionary - từ điển lớn nhất heapq trong python
Prerequisites: Show
Từ điển có thể được duy trì trong đống dựa trên khóa hoặc dựa trên giá trị. Các quy ước được duy trì được liệt kê dưới đây:
Examples:
Bài viết này cho thấy cách duy trì một từ điển trong một min-heap bằng mô-đun FEAPQ. Từ điển bình thường như một đốngTừ điển bình thường với số nguyên/chuỗi là khóa có thể được duy trì trong cấu trúc heap với sự trợ giúp của mô -đun FEAPQ. Nhưng mô -đun này hy vọng một danh sách sẽ được thông qua. Vì vậy, cách tiếp cận được sử dụng ở đây là:
LƯU Ý: Các heapify () trên các bộ dữ liệu xem xét phần tử đầu tiên trong tuple cho quy trình. Do đó, theo mặc định, các từ điển được duy trì trong đống, chỉ dựa trên khóa.The heapify() on tuples considers the first element in the tuple for the process. Thus, by default, the dictionaries are maintained in heap, based on the key only.The heapify() on tuples considers the first element in the tuple for the process. Thus, by default, the dictionaries are maintained in heap, based on the key only. Ví dụ 1: Dựa trên khóa cho số nguyên Hãy xem xét một từ điển trong đó các khóa là số nguyên dương và các giá trị là hình vuông của chúng. Bây giờ, điều này nên được duy trì trong một đống. Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}43 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}7 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}8 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}1 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}3 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}6 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}411 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Đầu ra After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}6 Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp; Hãy xem xét một từ điển có sự kết hợp của bảng chữ cái là khóa và đánh số của chúng là giá trị. Ví dụ: ABC ABC: 123. Điều này phải được duy trì trong Heap. & NBSP;abc” : 123. This has to be maintained in heap. abc” : 123. This has to be maintained in heap. Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}43 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}7 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}8 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}1 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}3 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}6 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}411 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Output:
Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp; value Hãy xem xét một từ điển có sự kết hợp của bảng chữ cái là khóa và đánh số của chúng là giá trị. Ví dụ: ABC ABC: 123. Điều này phải được duy trì trong Heap. & NBSP;abc” : 123. This has to be maintained in heap.
Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp;value Example: Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}43 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}7 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}8 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}1 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}3 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}6 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}5 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}411 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}2 Đầu ra Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp; After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}355 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}356 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}327 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}360 Hãy xem xét một từ điển có sự kết hợp của bảng chữ cái là khóa và đánh số của chúng là giá trị. Ví dụ: ABC ABC: 123. Điều này phải được duy trì trong Heap. & NBSP;abc” : 123. This has to be maintained in heap. Đầu ra After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}3 Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp;Hãy xem xét một từ điển có sự kết hợp của bảng chữ cái là khóa và đánh số của chúng là giá trị. Ví dụ: ABC ABC: 123. Điều này phải được duy trì trong Heap. & NBSP;abc” : 123. This has to be maintained in heap.
LƯU Ý: Các heapify () trên các bộ dữ liệu xem xét phần tử đầu tiên trong tuple cho quy trình. Do đó, theo mặc định, các từ điển được duy trì trong đống, chỉ dựa trên khóa.The heapify() on tuples considers the first element in the tuple for the process. Thus, by default, the dictionaries are maintained in heap, based on the key only.The heapify() on tuples considers the first element in the tuple for the process. Thus, by default, the dictionaries are maintained in heap, based on the key only. Ví dụ: & nbsp; Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}774 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}369 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}77 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}31 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}373 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}33 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}35 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}373 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}37 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}39 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}373 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}1 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}3 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}385 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}313 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}315 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}313 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}391 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}316 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}317 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}318 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}02 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}326 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}3 22 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}07 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}326 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}12 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}15 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}16 Đầu ra After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121} Từ điển lồng nhauTrong trường hợp từ điển lồng nhau, nhiệm vụ thực hiện nhiều bước hơn để duy trì từ điển trong đống. Nếu từ điển phải được duy trì dựa trên khóa trong từ điển bên trong, thì phương pháp sau đây có thể được sử dụng.
Ví dụ, hãy xem xét một hồ sơ của nhân viên là một từ điển lồng nhau. Hồ sơ xuất hiện như được đưa ra dưới đây: & nbsp;
& nbsp; & nbsp; & nbsp; & nbsp; "tuổi": 22, & nbsp; & nbsp; & nbsp; & NBSP; Chỉ định trực tuyến Python3& nbsp; & nbsp; & nbsp; & NBSP; & nbsp; & nbsp; After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}27 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}28 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}32 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}33 & nbsp; & nbsp; & nbsp; & nbsp; tên tên " Python3& nbsp; & nbsp; & nbsp; & NBSP; & nbsp; & nbsp;},& nbsp; & nbsp; & nbsp; & nbsp; tên của tên & nbsp; & nbsp; & nbsp; & nbsp; "tuổi": 20, After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}59 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}60 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}64 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}68 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}60 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}315 & nbsp; & nbsp; & nbsp; & NBSP; Chỉ định của người Viking & nbsp; & nbsp; & nbsp; & nbsp; "tuổi": 42, & nbsp; & nbsp; & nbsp; & NBSP; Chỉ định của người Viking: Người quản lý trực tuyến,& nbsp; & nbsp; & nbsp; & nbsp; tên tên "Step 2: Define the function that performs heapification. Takes the list of tuples as parameter.
After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}37 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}31517 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}35 Python3& nbsp; & nbsp;}Bây giờ đặt tất cả các mã với nhau, chúng tôi nhận được một từ điển lồng nhau được duy trì trong đống, dựa trên các giá trị của mức lương. Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}17 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}18 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}20 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}7____ After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}23 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}27 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}28 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}32 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}33 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}17 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}35 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}37 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}315 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}316 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}317 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}318 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}333 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}335 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}337 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}49 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}51 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}52 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}53 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}54 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}55 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}59 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}60 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}64 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}3 20 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4179 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}60 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}29 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}315 Is After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344___ After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}355 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}345 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}98 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}525 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}53 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}54 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}022 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}06 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}07 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}12 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}32 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}16 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}92 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}20 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}21 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}23 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}25 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}28 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}30 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}33 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}35 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}38 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}40 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}21 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}23 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}49 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}28 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}54 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}33 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}59 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}38 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}64 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}68 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}21 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}23 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}73 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}28 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}78 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344___ After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}38 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}88 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}92 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}21 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}23 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}97 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}28 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}78 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}33 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}83 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}344 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}38 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4112 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}4 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}4 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}20 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4118 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4121 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}16 Đầu ra
Chèn vào từ điển được duy trì dưới dạng một đốngViệc chèn các giá trị mới có thể được thực hiện trực tiếp bằng phương thức Heppush () trong mô -đun Heapq. Cú pháp của nó như sau.heappush() method in the heapq module. Its syntax is as follows.heappush() method in the heapq module. Its syntax is as follows.
Bây giờ, danh sách các bộ dữ liệu cùng với một tuple mới có thể được chuyển đến hàm này để thêm cặp giá trị khóa mới. Thí dụ : Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 Các After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}313 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}315 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}313 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}391 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}316 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}317 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}318 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4374 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}326 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}322 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4379 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}326 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}12 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}16 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4389 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}52 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}52 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4393 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4396 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}326 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}09 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}12 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4404 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}16 Output:
Một phương pháp khác có thể được thực hiện là có một chức năng tăng cường từ điển và gọi nó sau khi cập nhật từ điển. & NBSP; Thí dụ : Python3Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}41 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}42 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}17 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4409 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4411 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}7 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4414 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4416 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4411 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}410 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4421 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}320 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}414 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4426 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4427 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}92 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}77 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}31 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}33 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}35 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}37 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}39 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}300 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}1 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}778 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}3 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}4 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}030748 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4450 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4451 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}35 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}02 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4455 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4451 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}52 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}02 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}44 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}52 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4463 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4464 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}9 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}0 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4467 After extraction : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified key-value pairs : [(2, 4), (3, 9), (5, 25), (11, 121)] Heapified dictionaries : {2: 4, 3: 9, 5: 25, 11: 121}30 Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121}4450 Đầu ra Before adding new values Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} Updated dictionary : {11: 121, 2: 4, 5: 25, 3: 9, 4: 16, 1: 1} After adding new values Dictionary as heap : {1: 1, 2: 4, 5: 25, 3: 9, 4: 16, 11: 121} |