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

3. A sequence of numbers is non-decreasing if each number is at least as large a

ID: 3759042 • Letter: 3

Question

3. A sequence of numbers is non-decreasing if each number is at least as large as the one before it in the sequence. Write an algorithm in pseudo-code with the following input and output:

Input: a1, a2,..., an, a is a sequence of numbers where n 1.

Output: "True" if the sequence is non-decreasing and "False" otherwise.

4. Write an algorithm in pseudo-code with the following input and output:

Input: a1, a2,..., an, a is a sequence of numbers where n 1.

Output: "True" if there are any two numbers in the sequence whose sum is equal to 0. (hint: this needs a nested loop)

Explanation / Answer

1.

a= a1,a2,...an

for i from 1 to n-1

if !(a[i+1] >= a[i])

return FALSE

end for

return TRUE

2.

a= a1,a2,...an

for i from 1 to n

for j from 1 to n

if a[i] + a[j] == 0 then

return TRUE

end if

end for

end for

return FALSE

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