Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**Note: I have worked this question already—to no avail. I will post what I ha

ID: 3534716 • Letter: #

Question

**Note: I have worked this question already—to no avail. I will post what I have and shall include what I consider to be wrong, along with hints/tips teacher assistants and the instructor herself have given me. But if you are a MatLab pro and can do a better one—I’m all ears. The main issue here is that I CANNOT USE SORTING COMMANDS.

*The point of this assignment is to write the FASTEST POSSOBLE code/script that will give the answer. The actual length of the script does not matter (it can be short OR long)

Question :

Create a MatLab code/script (and algorithm) to sort a GIVEN ARRAY(vector) of numbers, i.e. [1, 2, 5, -10, 0, ...etc.] ; in other words, NOT a matrix. The instructor then says to "practice with 300 random numbers" for the assignment.

The actual amount of numbers to be sorted is unknown at this time, but-- what I am told is that it will be much larger *(the instructor told SWIM to sort 1000 numbers , but I am assuming a much larger number, and the numbers may or may not be rational or irrational).

His following statement explains that WE CANNOT USE SORTING COMMANDS. His next sentence implies that we need to WRITE OUR OWN ALGORITHM.

***The tricky part of this problem is that we cannot use sorting commands. No matter what, if you turn it in, you get extra credit—if not, then it does not affect me. But the most credit goes to those who have the code that computes the large array the fastest (in other words I need the fastest algorithm).

Here is what I have:

function dataOut = Sort(data)
lenD = size(data,2);

j = 1;
k = 1;

if(lenD<2)

dataOut = data;

else

pivot = data(ind);

for i=1:lenD

if(i~=ind)

if(data(i)<pivot)

L(j) = data(i);

j = j+1;

else

R(k) = data(i);

k = k+1;

end

end

end

L = Sort(L);

R =Sort(R);

dataOut = [L pivot R];

end

*^*^* I am willing to “work†with anyone who actually helps me out. Please leave a comment or somehow PM me so that we can get something going.

Explanation / Answer

function dataOut = Sort(data)
lenD = size(data,2);

j = 1;
k = 1;

if(lenD<2)

 dataOut = data;

else

 pivot = data(ind);

 for i=1:lenD

   if(i~=ind)

     if(data(i)<pivot)

       L(j) = data(i);

       j = j+1;

     else

       R(k) = data(i);

       k = k+1;

     end

   end

 end

 L = Sort(L);

 R =Sort(R);

 dataOut = [L pivot R];

end