Menu

[solved]-Hell Solve Matlab Many Thankss Part B Create Function Following Header Hints Hints Part B Q39054244

Hell SOLVE With MATLAB!! Many thankss
2 Merge Sort In this problem, you will implement the Merge Sort Algorithm to sort a 1-dimensional double array input argu- (aand part b) create a function with the following header
function [sortedArray] = mergeSort ( doubleArray) doubleArray is a lxn unsorted double array and sortedArray is the sorted vebelow are hints
%% Problem 2 % Merge Sort: Sorts an array by splitting it into two arrays, sorting each % of them recursive ly, and then combhints to part b) this is where Recusion comes in
% This function takes in an UNSORTED array and returns % ascending order). a SORTED ar ray (in % Split big array into two sma2 Merge Sort In this problem, you will implement the Merge Sort Algorithm to sort a 1-dimensional double array input argu- (a) Write a nested function called combine2Arrays which takes as ments two arrays- array1 and array2 combinedArray. array1 must be a lxn sorted double array, and array2 must be a 1xm sorted double array. The function should return a array which is also sorted. Your code should be able to reproduce the following and returns an output argument combined test case: [1 3 51 [2 4] >>combine 2 Arrays (a , b) >> a >>b ans 12 3 45 function [sortedArray] = mergeSort ( doubleArray) doubleArray is a lxn unsorted double array and sortedArray is the sorted version of doubleArray. In order to achieve merge sort, you will split the ar- ray into two sub-arrays of roughly equal size., recursively sort them, and then combine the two sorted sub-arrays. For example, if doubleArray is 10,8,3,8,6,1] then your code should split this into two sub-arrays: [10,8,3) and [8,6,1]. Recursively sorting the sub-arrays should return 3,8,10 and 1,6,8]. Then your code should combine these us- ing the combine2Arrays function that you wrote to return the sortedArray 1,3,6,8,8,10]. You can test your code by supplying mergeSort, and checking that the output is indeed the correct sorted version of the arbitrary unsorted array doubleArray to an array. Submit the code of this problem in the file mergeSort.m. %% Problem 2 % Merge Sort: Sorts an array by splitting it into two arrays, sorting each % of them recursive ly, and then combining them back. % Part ( a) : NESTED function % Part (b): MAIN function % function % Main function : Does some thing . % function % Nested function : Does something. % Nested function can access everything that the main function has. % end % end % Part (a) % Input arrays are both SORTED. (Sorted in ascending order) % Combine them and return the overall SORTED array. % You should NOT be using any sort function, but doing this using basic % principles you learnt about arrays, logical statements, loops % For the nested function, you should NOT be using recursion . This is just % a standard function . % Think of how you would do this on paper, and you would get a hint of how % to write the code for it. % This function takes in an UNSORTED array and returns % ascending order). a SORTED ar ray (in % Split big array into two smaller arrays RECURSIVELY sort them (call % your function with those new arrays as the input arrays ), and then % combine the two sorted arrays using your part (a) function % BASE CASE (Important) Has to be some thing very simple. % Check that the test case I gave you works. % SECONDLY, that test case has 6 elements good split into 3 and 3 % Try a test case with only 5 elements one will have 2, one will have 3. % Your code should be able to work, regardless of whether your array has odd % or even number of elements. % THIRDLY , you can supply any unsorted array as % mergeSort should be the sorted array. input, and the output of Show transcribed image text 2 Merge Sort In this problem, you will implement the Merge Sort Algorithm to sort a 1-dimensional double array input argu- (a) Write a nested function called combine2Arrays which takes as ments two arrays- array1 and array2 combinedArray. array1 must be a lxn sorted double array, and array2 must be a 1xm sorted double array. The function should return a array which is also sorted. Your code should be able to reproduce the following and returns an output argument combined test case: [1 3 51 [2 4] >>combine 2 Arrays (a , b) >> a >>b ans 12 3 45
function [sortedArray] = mergeSort ( doubleArray) doubleArray is a lxn unsorted double array and sortedArray is the sorted version of doubleArray. In order to achieve merge sort, you will split the ar- ray into two sub-arrays of roughly equal size., recursively sort them, and then combine the two sorted sub-arrays. For example, if doubleArray is 10,8,3,8,6,1] then your code should split this into two sub-arrays: [10,8,3) and [8,6,1]. Recursively sorting the sub-arrays should return 3,8,10 and 1,6,8]. Then your code should combine these us- ing the combine2Arrays function that you wrote to return the sortedArray 1,3,6,8,8,10]. You can test your code by supplying mergeSort, and checking that the output is indeed the correct sorted version of the arbitrary unsorted array doubleArray to an array. Submit the code of this problem in the file mergeSort.m.
%% Problem 2 % Merge Sort: Sorts an array by splitting it into two arrays, sorting each % of them recursive ly, and then combining them back. % Part ( a) : NESTED function % Part (b): MAIN function % function % Main function : Does some thing . % function % Nested function : Does something. % Nested function can access everything that the main function has. % end % end % Part (a) % Input arrays are both SORTED. (Sorted in ascending order) % Combine them and return the overall SORTED array. % You should NOT be using any sort function, but doing this using basic % principles you learnt about arrays, logical statements, loops % For the nested function, you should NOT be using recursion . This is just % a standard function . % Think of how you would do this on paper, and you would get a hint of how % to write the code for it.
% This function takes in an UNSORTED array and returns % ascending order). a SORTED ar ray (in % Split big array into two smaller arrays RECURSIVELY sort them (call % your function with those new arrays as the input arrays ), and then % combine the two sorted arrays using your part (a) function % BASE CASE (Important) Has to be some thing very simple. % Check that the test case I gave you works. % SECONDLY, that test case has 6 elements good split into 3 and 3 % Try a test case with only 5 elements one will have 2, one will have 3. % Your code should be able to work, regardless of whether your array has odd % or even number of elements. % THIRDLY , you can supply any unsorted array as % mergeSort should be the sorted array. input, and the output of

Expert Answer


Answer to Hell SOLVE With MATLAB!! Many thankssand part b) create a function with the following header below are hintshints to par… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *