Discrete math question Need response ASAP Please don\'t answer if you don\'t kno
ID: 3843694 • Letter: D
Question
Discrete math question Need response ASAP Please don't answer if you don't know 4. a) Describe a non-recursive algorithm that takes a list of distinct integers ai,a, a, and retums the number of positive integers in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, E.g. For the list-2, 9, -5, 3,-1 your program should retum 2, because the list contains two positive integers. procedure Number of Positives (a,a,.....a, integers) b) Describe a recursive algorithm that takes a list L of distinct integers and retums 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) "first" which returns the given nonempty list. first element of a ii) "rest" which retums 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 Positives (L :list ofintegers)Explanation / Answer
Let me know if you have any doubt.
Answer 4 a) python procedure( non-recursive):
Number_of_Positives(integer_list):
num_int=0
for num in integer_list:
if num >= 0:
num_int++
return num_int
Answer 4 b) python procedure( recursive):
min=0
Number_of_Positives(L):
if empty(L):
return TRUE
Number_of_Positives(rest)
if min > first and first >=0:
min=first
return min
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.