Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(e) Using recursion, write a Python function: def exist (A, i, f) which takes as input an array A of integers, a positive integer i,
(e) Using recursion, write a Python function: def exist (A, i, f) which takes as input an array A of integers, a positive integer i, and a function f that takes as input an integer and returns a boolean. The function exist returns True if there are at least i elements x in A such that f(x) returns True. If A is empty, exist(A,i,f) should return false. For example, if isOdd is a function that returns True on odd integer inputs and False otherwise, then exist([1,2,3],1,odd) and exist([1,2,3] ,2, odd) should return True (1 and 3 are odd), while exist([1,2,3] ,3, odd) should return false. [5 marks]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started