Question: 1.) ARGUMENT OF CORRECTNESS FOR CODE 2.) RUNTIME ANALYSIS FOR CODE CODE: '''returns the largest integer x such that x^k does not exceed n, assuming

1.) ARGUMENT OF CORRECTNESS FOR CODE

2.) RUNTIME ANALYSIS FOR CODE

CODE:

'''returns the largest integer x such that x^k does not exceed n,

assuming k and n are both positive integers'''

def iroot(k, n):

num=1

#looping until num^k is greater than n

while True:

#checking if current number ^ k is greater than n

if pow(num,k)>n:

#returning previous number

return num-1

#moving to next number

num+=1

#testing various cases

print(iroot(3,125)) #5

print(iroot(3,126)) #5

print(iroot(3,124)) #4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!