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 mergelinkedlistssrtlnklst srtlnklst
This function is given two doubly linked lists of integers srtlnklst and
srtlnklst The elements in srtlnklst and srtlnklst 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 srtlnklst
and srtlnklst
calling: mergelinkedlistssrtlnklst srtlnklst should
create and return a doubly linked list that contains:
The mergelinkedlists function is not recursive, but it defines and calls
merge
sublists a nested helper recursive function.
Complete the implementation given below for the mergelinkedlists
function:
def mergelinkedlistssrtlnklst srtlnklst:
def merge
sublists
:
return merge
sublists
Notes:
You need to decide on the signature of merge
sublists.
merge
sublists has to be recursive.
An efficient implementation of merge
sublists
would allow
mergelinkedlists 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
