(21 points) Given singly linked lists, each of which has nodes. The numbers in the nodes of the -th list are given by , as shown in the figure below. Each of the lists has the numbers sorted in non-decreasing order, i.e., , where is the index of the list. Professor Q asks the students to develop an algorithm to merge these k lists into one singly linked list sorted in non-decreasing order. Three students have come up with different algorithms, which are given below in pseudo code.
Student A: L1. Create an empty singly linked list to collect the result. L2. DO L3. Iterate over the numbers in the head nodes of the lists, and find the node with the smallest number, denoted as node . L4. Remove node from the original list, and insert it into the result list from the tail. L5. UNTIL all original lists are empty L6. Return the result list , which contains all nodes from the original lists and sorted in non-decreasing order.
Student B: L1. Create an empty singly linked list to collect the result. L2. Create an empty min heap . L3. Remove the head nodes from the lists and insert them into . Each node in also contains the index number of the list where it is from. L4. DO L5. Remove the min node from the heap. Insert this node into from the tail. Take note of the index number stored in , denoted as . L6. If list is not empty, remove the head node from list and insert it into . L7. WHILE is not empty L8. Return the result list , which contains all nodes from the original lists and sorted in non-decreasing order.
Student C: Call the recursive divide-and-conquer function MergeTwoGroupLists ( sorted linked lists). The return value of the function is a list containing all nodes from the original lists and sorted in non-decreasing order.
L1. Function MergeTwoGroupLists ( sorted linked lists) L2. If then return the only list from the input. L3. Divide the input lists into two groups of lists, with and lists, respectively. L4. Recursively call MergeTwoGroupLists for each of these two groups of lists, merging the first group of the lists into one sorted list, , and the second group of the lists into one sorted list, . L5. Merge the two sorted lists and into one sorted list . L6. Return .
For each of these three algorithms, analyze and give their asymptotic worst-case running times with the big-O notation and in terms of and .
Note:
- Lower-order terms and constant factors (excluding and ) should be removed in the big-O notation in the answer.
- The bound in the answer needs to be tight.
- Only the final result will be graded and only fully correct answers will be given points. Please clearly mark your final result in the answer sheet.