Question: In this question, we will implement a function that merges two sorted linked lists: def merge _ linked _ lists ( srt _ lnk _

In this question, we will implement a function that merges two sorted linked lists:
def merge_linked_lists(srt_lnk_lst1, srt_lnk_lst2)
This function is given two doubly linked lists of integers srt_lnk_lst1 and
srt_lnk_lst2. The elements in srt_lnk_lst1 and srt_lnk_lst2 are sorted.
That is, they are ordered in the lists, in an ascending order.
When the function is called, it will create and return a new doubly linked list, that
contains all the elements that appear in the input lists in a sorted order.
For example:
if srt_lnk_lst1=[1<-->3<-->5<-->6<-->8],
and srt_lnk_lst2=[2<-->3<-->5<-->10<-->15<-->18],
calling: merge_linked_lists(srt_lnk_lst1, srt_lnk_lst2), should
create and return a doubly linked list that contains:
[1<-->2<-->3<-->3<-->5<-->5<-->6<-->8<-->10<-->15<-->18].
The merge_linked_lists function is not recursive, but it defines and calls
merge
sublists - a nested helper recursive function.
_
Complete the implementation given below for the merge_linked_lists
function:
def merge_linked_lists(srt_lnk_lst1, srt_lnk_lst2):
def merge
sublists(
_
___________________________):
______________________________________________
______________________________________________
______________________________________________
______________________________________________
______________________________________________
return merge
sublists(
)
_
______________________________
Notes:
1. You need to decide on the signature of merge
_
sublists.
2. merge
sublists has to be recursive.
_
3. An efficient implementation of merge
sublists _
would allow
merge_linked_lists to run in linear time. That is, if ! and " are the sizes
of the input lists, the runtime would be (!+").

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!