Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To calculate the factorial of a function the following recursive function can be used. def factorial ( n ) : if n = 0 :

To calculate the factorial of a function the following recursive function can be used. def factorial(n):
if n=0 :
return 1
else:
return n** factorial(n-1)
How many times will the function be called to calculate the factorial of 5?
a)6
b)5
c)4
d)3
The following binary_search function is used to find a target in a sorted list.
def binary_search(data, target, low, high):
""'Return True if target is found. """
if low>high:
return False
else:
mid =(low+high)??2 #division floor
if target == data[mid]: #found a match
#base case
return True
elif target=4n=len0,n-1 data =[2,4,7,8,9,12,14,17,19,22,25,27,28,33,37]
target =4
n=len (data)
print(binarysearch(data, target, 0,n-1))
What will be the value of 'mid' at the second binarysearch function call?
a
image text in transcribed

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

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions