Hướng dẫn heap dictionary python - heap từ điển 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. 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. Python3
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 = 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 = import 0import 1After 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 import 4Before 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 dictionary into list : [(11, 121), (2, 4), (5, 25), (3, 9)] Heapified list of tuples : [(2, 4), (3, 9), (5, 25), (11, 121)] Dictionary as heap : {2: 4, 3: 9, 5: 25, 11: 121} 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. Python3
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 = 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 = import 0import 1After 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 import 4Before 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;
Cách tiếp cận hơi khác nhau ở đây. Các bước được thực hiện là: Example: Python3
Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}13 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}5 = 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}21 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}25 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}27 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}5 = import 0import 1Đầu ra Ví dụ 2: Dựa trên khóa cho chuỗi & nbsp; Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}55 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}56 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}27 = import 0Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}60 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; Đầu ra Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121} 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;
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. Ví dụ: & nbsp; Python3
Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}69 11 11 8Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}1 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}73 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}3 11 8Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}5 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}73 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}7 11 8Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}9 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}1 11 8After 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}85 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}13 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}13 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}91 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}16 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}17 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 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 = import 0After 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": 42, & nbsp; & nbsp; & nbsp; & NBSP; Chỉ định của người Viking: Người quản lý trực tuyến, Python3& nbsp; & nbsp; & nbsp; & NBSP; & nbsp; & nbsp; Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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; Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}37 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 & nbsp; & nbsp;} } Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}64 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}09 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 Bây giờ chúng ta hãy duy trì điều này trong một min-heap dựa trên các giá trị lương. Do đó, nhân viên có mức lương tối thiểu xuất hiện dưới dạng kỷ lục đầu tiên. Để dễ đọc và hiểu rõ hơn, chúng ta có thể chia mã thành các chức năng. Bước 1: & nbsp; Xác định chức năng để chuyển đổi từ điển thành danh sách & 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}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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}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 & nbsp; Bước 2: Xác định chức năng thực hiện quá trình hấp thụ. Lấy danh sách các bộ dữ liệu làm tham số. & 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}16 = { Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}35 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}21 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}16 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}17 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}18 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}0 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}35 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}37 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8import 12Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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 = import 18After 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 = import 21After 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 import 4After 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 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. Python3
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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}37 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}16 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}17 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}18 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}0 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}35 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}37 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}64 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 import 79After 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}09 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 Is Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}44___ Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}55 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}45 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}09 = import 0Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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 = { Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}35 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}21 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}44___ Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}42 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}23 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}28 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}33 11 8Before 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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 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}38 11 8import 12Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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}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 = import 18After 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 = import 21After 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 import 4After 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.
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ụ : Python3
Các Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}13 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}15 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}13 = Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}91 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}16 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}17 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}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 dict_1 74Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 dict_1 79Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 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 = import 0After 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 import 4After 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
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 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 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 dict_1 93After 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 dict_1 96Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}26 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 = import 0After 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 = 04After 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ụ : Python3
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 = 09Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 = 11= 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 = 14Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 = 16Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}20 = 11= import 0= 21Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}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 import 4= 26
Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}1 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}3 11 8Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}5 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}7 11 8Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}9 Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {2: 4, 3: 9, 5: 25, 11: 121}00 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 11 8After 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
Values of the dict after heapification : [4, 9, 25, 121] Final dictionary : {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}02 = = 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}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 = 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 = 63= 64After 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 = 67After 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
Đầ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} |