Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a Python function: def oddest (A , B ) that takes as input two arrays A and B of integers and returns: 1

1. Write a Python function: def oddest (A , B ) that takes as input two arrays A and B of integers and returns: 1 if A has more odd elements than B, 2 if B contains more odd elements that A, 0 if the two arrays contain the same number of odd elements. For example, oddest([1,3,5],[5,2,3,0]) should return 1, and oddest([5,2,3,0],[1,3,5]) should return 2. On the other hand, oddest([1,3,5],[5,2,3,7]) should return 0. Note: in Python, the remainder of dividing x by y is computed by x%y.

2. Using recursion, write a Python function: def exists (A , f ) which takes as input an array A of integers and a function f that takes as input an integer and returns a boolean. The function exists returns True if there is at least one element x in A such that f(x) returns True. If A is empty, exists(A,f) should return False. For example, if isOdd is a function that returns True on odd integer inputs and False otherwise, then exists([1,2,3],odd) should return True (1 and 3 are odd), while exists([0,2,42],odd) should return False (neither of 0,2,42 is odd).

3. Using recursion, write a Python function: def merge (A , B ) which takes as input two sorted arrays A and B of integers and returns a new sorted array containing the elements of both A and B. For example, merge([1,4,6],[2,3,4,7]) should return [1,2,3,4,5,6,7]. Note: You might find useful to define an auxiliary function mergeRec(A,B,C,lo) that merges A and B into the part of C from position lo to position len(C)-1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions