Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write a recursive function BrainSearch that takes three parameters: an array, starting position, and the number to search. It returns the location of a
1. Write a recursive function BrainSearch that takes three parameters: an array, starting position, and the number to search. It returns the location of a number if exists in the array, otherwise returns -1. The function works as per the following recursive definition: - If loc is greater than number of elements than returns -1 - if element e found at location loc' in the array then returns the location, - Otherwise, perform BrainSearch again for location loc+1 def BrainSearch(array, loc, e): // your code goes here Example: array = [11, 32,13, 41,51] print (BrainSearch(array, 0, 13)) print (BrainSearch(array,0, 16) ) #the function should return 2 -1 2. Write a function RotateRight that rotates an array of size n to the right. The function takes two parameters an integer d which is the amount to rotate by and an array. The function should return the rotated array. def RotateRight (array, d): // your code goes here Example: array = [1,2,3,4,5) d = 2 #two rotations print (RotateRight (array,d)) #the function should return [4,5,1,2,3]
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