Question: function merge_sort(list m) // if list size is 0 (empty) or 1, consider it sorted and return it // (using less than or equal prevents

function merge_sort(list m) // if list size is 0 (empty) or 1, consider it sorted and return it // (using less than or equal prevents infinite recursion for a zero-length m) if length(m) <= 1 return m // else list size is > 1, so split the list into two sublists var list left, right var integer middle = length(m) / 2 for each x in m before middle add x to left for each x in m after or equal middle add x to right // recursively call merge_sort() to further split each sublist until sublist size is 1 left = merge_sort(left) right = merge_sort(right) // merge the sublists returned from calls to merge_sort() and return the resulting merged sublist return merge(left, right) function merge(left, right) // set up a 'result' variable for the merged result of two sublists. var list result // assign the element of the sublists to 'result' variable until there is no element to merge. while length(left) > 0 or length(right) > 0 if length(left) > 0 and length(right) > 0 // compare the first two element, which is the small one of each two sublists. if first(left) <= first(right) // the small element is copied to 'result' variable. // delete the copied one (a first element) in the sublist. append first(left) to result left = rest(left) else // same operation as the above (in the right sublist). append first(right) to result right = rest(right) else if length(left) > 0 // copy all remaining elements from the sublist to 'result' variable, // when there is no more element to compare with. append first(left) to result left = rest(left) else if length(right) > 0 // same operation as the above (in the right sublist). append first(right) to result right = rest(right) end while // return the result of the merged sublists (or completed one, finally). return result Draw the corresponding graph and label the nodes as n1, n2, and edges as e1, e2

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 Databases Questions!