https://github.com/lesiaukr/goit-algo-hw-08
Master's | Basic Algorithms & Data structures | Module 8 | Heaps or Pyramids
https://github.com/lesiaukr/goit-algo-hw-08
heapq heaps heapsort-algorithm
Last synced: 3 months ago
JSON representation
Master's | Basic Algorithms & Data structures | Module 8 | Heaps or Pyramids
- Host: GitHub
- URL: https://github.com/lesiaukr/goit-algo-hw-08
- Owner: LesiaUKR
- Created: 2024-07-19T10:31:09.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-20T12:01:38.000Z (11 months ago)
- Last Synced: 2025-01-29T23:16:18.516Z (5 months ago)
- Topics: heapq, heaps, heapsort-algorithm
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# goit-algo-hw-08
# Homework Assignment on Heaps or Pyramids
## Task 1
### Description of the AssignmentImagine you are given the following task in a technical interview, which you need to solve using a heap.
There are several network cables of different lengths, and they need to be joined two at a time into a single cable using connectors, in a way that will result in the lowest total cost. The cost of connecting two cables equals the sum of their lengths, and the total cost is the sum of connecting all cables.
The task is to find the order of joining the cables that minimizes the total cost.
## Optional Task 2
Given k sorted lists of integers. Your task is to merge them into a single sorted list. For this task, you should use a min heap to efficiently merge multiple sorted lists into one sorted list. Implement a function merge_k_lists that takes a list of sorted lists as input and returns a single sorted list.
### Example Expected Result:
```
lists = [[1, 4, 5], [1, 3, 4], [2, 6]]
merged_list = merge_k_lists(lists)
print("Sorted list:", merged_list)```
Output:```
Sorted list: [1, 1, 2, 3, 4, 4, 5, 6]```
## Acceptance CriteriaThe code must execute and return the minimum possible total cost.