Skip to content

Commit cd20b4d

Browse files
committed
added reference and desc for merge_k_sorted_list algo
1 parent a31e187 commit cd20b4d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

data_structures/linked_list/merge_k_sorted_list.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
""" This algorithm merges k sorted linked lists into a single sorted linked list.
2+
3+
Each input linked list is assumed to be sorted in non-decreasing order. The algorithm uses a min-heap (priority queue) to efficiently determine the next smallest node among all the heads of the lists.
4+
5+
At every step:
6+
7+
The smallest element among the current nodes of all lists is extracted from the heap.
8+
9+
That node is appended to the result list.
10+
11+
The next node from the same list (if any) is then pushed into the heap.
12+
13+
This process repeats until all nodes from all lists have been processed.
14+
The final result is a single sorted linked list containing all elements from the input lists.
15+
16+
Solve on:
17+
https://leetcode.com/problems/merge-k-sorted-lists/
18+
"""
119
from __future__ import annotations
220
from collections.abc import Iterable, Iterator
321
from dataclasses import dataclass
@@ -90,3 +108,6 @@ def merge_k_sorted_lists(lists: list[SortedLinkedList]) -> SortedLinkedList:
90108

91109
print("Merged K Sorted Lists:")
92110
print(merged_k)
111+
112+
'''
113+
'''

0 commit comments

Comments
 (0)