Need Help ?

Home / Expert Answers / Other / in-r-programming-a-read-through-the-following-pseudocode-function-merge-inputs-left-right-two-sorted

(Answered): IN R Programming (a) Read through the following pseudocode: FUNCTION: merge() INPUTS: left, right, t ...



IN R Programming

(a) Read through the following pseudocode: FUNCTION: merge() INPUTS: left, right, two sorted numeric vectors OUTPUT: A single

(a) Read through the following pseudocode: FUNCTION: merge() INPUTS: left, right, two sorted numeric vectors OUTPUT: A single combined sorted vector merged <- numeric vector of length 0. WHILE length of left > 0 IF length right > 0 If the first element of left < the first element of right merged <- combination of merged and the first element of left remove the first element of left ELSE merged <- combination of merged and the first element of right remove the first element of right ELSE merged <- combination of merged and left remove all the elements of left RETURN combination of merged and right FUNCTION: merge_sort() INPUTS: x, a numeric vector OUTPUT: A vector containing the elements of x, sorted from smallest to largest. IF length x > 1 split x roughly into half, as two vectors named left and right sorted_left <- left sorted by merge_sort() sorted_right <- right sorted by merge_sort() x <- merge sorted_left and sorted_right with the merge() function RETURN x Using the provided pseudocode, write the merge () and merge_sort() functions.


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to (a) Read through the following pseudocode: FUNCTION: merge() INPUTS: left, right, two sorted numeric vectors OUTPUT: A s...
We have an Answer from Expert

Buy This Answer $4

Place Order