sec13 - CS100M Section Exercise 13 1 Merge Sort a= [4 1 6 3...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS100M Section Exercise 13 1 Merge Sort The code for MergeSort and the function header for Merge are shown below. Trace the execution of the script a=[4163295760]; b= MergeSort(a); For each call of the MergeSort and Merge , write down the arguments that are passed to the function and the values that are returned. The code below displays the values in vectors y1 and y2 and they are the values returned by speci±c calls to MergeSort . Notice that multiple instances of the same function may be open at one time—which function has this behavior, MergeSort or Merge ? Ask your section instructor if you have any questions! function y = MergeSort(x) % x is a column n-vector. % y is a column n-vector consisting of the values in x sorted % from smallest to largest. n = length(x); if n==1 y=x ; else m = floor(n/2); % Sort the first half. . y1 = MergeSort(x(1:m)) % values displayed are the values returned by this call of MergeSort % Sort the second half. .. y2 = MergeSort(x(m+1:n)) % values displayed are the values returned by this call of MergeSort % Merge. ..
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

sec13 - CS100M Section Exercise 13 1 Merge Sort a= [4 1 6 3...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online