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

For all these programming exercises you will have to use all the programming tip

ID: 663661 • Letter: F

Question

For all these programming exercises you will have to use all the programming tips and principles that we have discussed. A complete solution for each of these problems will include:

? For the program itself:

o A header (commented out in the program) that includes:

§ Your name

§ Brief description of the program including input(s) and output(s) § Date it was created

§ Date of last modification

§ Anything else you might find important to include

o Comments throughout the program to describe some steps or notes for yourself

? appropriate test cases with results copied and pasted in the Word file.

1. Select one method from the list below and code it in MATLAB. The corresponding pseudocode can be found in the lecture 8 slides. The program should use an array of at least 10 elements that you define at the beginning of the program (no need to ask the user, just assign the values to the array in the program).

*Searching arrays:

-Serial search

-Binary search

*Sorting arrays:

-Bubble sort

-Selection sort

Explanation / Answer

Binary Search
function result = bin_search(l, num)
result = -1;
low = 0
high = size(l)-1;
while (low <= high)
mid = (low+high)/2;
if (l[mid] > num)
high = mid-1;
continue;
if
low = mid + 1
continue;
else
result = mid;
break;
end
end
result;
end

Bubble sort

function l = bub_sort(l)
n = length(l);
while (n > 0)
n_new = 0;
for i = 2:n
if (l(i) < l(i-1))
temp = l(i);
l(i) = l(i-1);
l(i-1) = temp;
n_new = i;
end
end
n = n_new;
end
l;
end

Bubbl Sort

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote