Question: Matlab How can i improve this function if code to call my function y = reversal(1:1e6); We spent some time on the my_flip problem, the
Matlab
How can i improve this function if code to call my function y = reversal(1:1e6);
We spent some time on the my_flip problem, the one about flipiing the elements of a vector. Earlier in this course, you had to solve it recursively. There we called it reversal. Your code may have looked like this: function v = reversal(v) if length(v) > 1 V = [v(end) reversal(v(1:end-1))]; end end This works well for smaller inputs but what if we have a really long vector? MATLAB may run out of stack space and even if not, it will be relatively slow due to the many many function calls. Your mission, should you choose to accept it, is to improve this recursive implementation to make it fast and to make it work on long vectors too. Again, it needs to stay recursive; it just cannot have as many nested recursive calls as the number of elements the list has! (Hint one of the algorithms we looked at this lesson, even though it is seemingly unrelated, may give you an idea...)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
