Given below is the code (tested on python 3.5) for the
question.
************ EVERYTHING IS DONE. YOU JUST NEED TO COPY THE
bintest() FROM YOUR PROJECT 6-1 AS MENTIONED IN QUESTION.. SINCE
YOU HAVE NOT GIVEN THAT CODE, I HAVE JUST LEFT PLACE WITH COMMENT
WHERE YOU NEED TO COPY THE bintest()*****************
Make sure to indent the code exactly as shown in image. INDENTATION
IS LOST WHEN CODE IS UPLOADED ON CHEGG SITE
Please don't forget to rate the answer if it was helpful. Thank
you
Let me know in case you need some help to integrate your previous
code into this one.
#iterative function
def isMemberI(aseq, target):
start = 0
end = len(aseq) - 1
while start <= end:
mid = (start + end) // 2
if aseq[mid] == target:
return True
elif target < aseq[mid]:
end = mid - 1
else:
start = mid + 1
return False
#recursive function
def isMemberR(aseq, target):
if not aseq:
return False
mid = (len(aseq) - 1) // 2
if target == aseq[mid]:
return True
elif target < aseq[mid]:
return isMemberR(aseq[0, mid], target)
else:
return isMemberR(aseq[mid+1:], target)
#function bintest TO COPY FROM project 6
def bintest():
#TODO
return
def main():
bintest(isMemberR)
print()
bintest(isMemberI)
print()
return None
main()
Requirements Write functions isMemberR, a recursive function, and isMemberI, which will use an iterative approach, to...
Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...
please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....
**IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...
DO NOT use for loop and while loop Goal: Learn how to use recursive functions. General requirement: Use cout to fully demonstrate your works for all tasks. The output must clearly show how each of these functions work. If no output is displayed for a task below, 0 point will be given to the task. If the output is not clear, some points may be deducted. Task 1 – Reverse array (3 pts) Given an integer array like: const...
can somebody help me with this exercise 5 Euclidean algorithm The largest common divisor (gcd) of two positive integers p and q can be given by the Euclid's algorithm explained in the lecture will be determined. · Write a function gcdIterative that uses the largest common divisor of p and q Calculates loop structure and returns. Use the pseudocode given in the lecture as a starting point and implement it as directly as possible into a C ++ program. Use...
Write a recursive function that takes a string as an input and returns the reverse of the string. Write a recursive function rec_string that produces the output shown below for the corresponding function calls. Write a main function to test the function. Method call rec_string(‘abcde’), will produce the following output: * e de cde bcde abcde Method call rec_string(‘abc’), will produce the following output: * c bc abc
Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func) (cond ((null? input-list) '()) ((func (car input-list)) (cons (car input-list) (filter (cdr input-list) func))) (else (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...
(a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...
Write a program that meets the following criteria: Define a function that implements the selection sort algorithm to sort an integer array. Define a function that implements the binary search algorithm to search an array for a given integer. The function must return the location of the integer if it is found or a -1 if it is not found. The main function in your program must declare an integer array initialized with 10 unsorted values. The main function must...
Implement the algorithm maxArray, discussed in Section 2.4.3, as a C++ function. Make sure the following requirements are met. Program must compile and run. maxArray function must be a recursive template function. Add a main function to test the maxArray function so that you have a complete program. Test the maxArray function on two arrays of different types. Name the program maxarray.cpp. Make sure the following requirements are met. 2.4.3 Finding the Largest Value in a Sorted or Unsorted Array...