For all these programming exercises you will have to use all the programming tip
ID: 663667 • 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. code it in MATLAB. The corresponding pseudocode can be found below. 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
General
Pseudocode
for the
Serial Search
1.
//
Set the subscript (
Index
) of the current key to 0
2.
Set
Index
= 0
3.
//
Set a flag (
Found
) to 0
4.
Set
Found
= 0
5.
While
(
Found
== 0) AND (
Index
<
N
)
6.
If
KeyData
[Index]
==
Key
Then
7.
Set
Found
= 1
8.
End If
9.
Set
Index
=
Index
+ 1
10.
End
While
11.
If
Found
== 1 Then
12.
Write
KeyData
[Index
–
1
]
13.
Else
14.
Write “The item you are searching for was not found.”
15.
End
If
-Binary search
.
Given
an array,
A
, with
N
elements:
2.
While
(array
A
is not sorted)
3.
For (
K
= 0;
K
<
N
–
1;
K
++)
4.
If
A[K]
>
A[K
+ 1
]
Then
5.
Interchange
A[K] and A[K+ 1]
6.
End If
7.
End For
8.
EndWhile
*Sorting arrays:
-Bubble sort
-Selection sort
Explanation / Answer
binary search.m function [binary_location] = searchBinary(name, searchpath, err_fail) if (narginRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.