Question: A) Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ..., a_n and returns the number of even integers in the

 A) Describe a non-recursive algorithm that takes a list of distinct

A) Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ..., a_n and returns the number of even integers in the list. Write your answer in pseudo-code or any well-known procedural language like Python. Java. C++, .... Assume that a function to determine whether an integer is even or not is already built into your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 3. because there are three even numbers in that list. procedure Number of Evens (a_1, a_2, ..., a_n: integers) b) Describe a recursive algorithm that lakes a list L of distinct integers and returns the number of even integers 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 a built in way to determine whether a number is prime or not, and 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_Evens (L: list of integers)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!