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

a) Describe a Don-recursive algorithm that takes a list of distinct integers a_l

ID: 3141615 • Letter: A

Question

a) Describe a Don-recursive algorithm that takes a list of distinct integers a_l, a_2 a, , a_n and returns the number of positive integers in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C^++, E.g. For the list -2, 9, -5, 3, -l your program should return 2, because the list contains two positive integers. procedure Number of Positives (a_1, a_2, , a_n: integers) b) Describe a recursive algorithm that takes a list L of distinct integers and returns the the smallest positive number in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C^++, You may assume that your language has the following built in functions to manipulate lists. i)"empty?" which returns TRUE if a given list is empty, FALSE otherwise ii) "first" which returns the first element of a given nonempty list. iii) "rest" which returns a list containing all but the first element of a given nonempty list. Note that if the list has only one element, "rest" will return the empty list. Procedure Number_of_Positive (L: list of integers)

Explanation / Answer

Ans(4.a):
ALGORITHM TO COUNT NUBER OF POSITIVE INTEGERS IN GIVEN LIST OF INTEGERS

START
n=0;
count=0;   // variable for counting number of positive integers
decision = Y;

while(decision=y)
{
Input the number n=";
if n>0 then count=count+1;
If you want to input more numbers then press y?
input decision=;
}
End while loop.

display result
total number of even numbers in the list = count;

END

-----------------

Ans(4.B):

Similarly you can take input for the list and assume variable smallest = 0

now apply the check condition for the entered number "n"

if n<smallest then smallest=n;

keep looping that condition until you are out of numbers then that will be your answer :)