Question

import time def sumkCk): time.time() start total for i in range(k+1): total i time.time() total end return total, end-start fCan someone explain this? And tell me what is sumk function,and how relate to recursion

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

sumk is an iterative function to find the sum of first k integers where k is passed as parameter and it is then returned from the function

It can be related to recursion by changing the function as

def sumk(k):

if(k==0):

return 0;

else:

return k+sumk(k-1);

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Can someone explain this? And tell me what is sumk function,and how relate to recursion import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone explain to me how I can determine the functional group and how to tell...

    Can someone explain to me how I can determine the functional group and how to tell what the numbers for the different stretching have to do with determining it? $5) What functional groups are represented in the following IR spectrum 00T SD 4D00 3000 20DB 1000 a0 AVENUMEERI

  • Using Python3, How can I aggregate the output from each iteration to one single list? Because...

    Using Python3, How can I aggregate the output from each iteration to one single list? Because from the program I have right now, it gives me the result of every iteration and gives me something like this as individual results and not one large list: None None ... None 130.0 None ... 1764 1765 None To clarify, I have this program where it calculates the sum of bytes sent within each incrementation of every 1 second, but there are instances...

  • PLEASE HELP ASAP! in Python, I am supposed to create a program that compares insertion sorting...

    PLEASE HELP ASAP! in Python, I am supposed to create a program that compares insertion sorting and selection sorting. My program only compares insertion and selection once. It is supposed to compare increasing, decreasing and an array of random values for each at 5 different lengths (without looping). Please help me. I have included my code below. import time import random def insertion_sort(arr):     for i in range(1, len(arr)):         key = arr[i]         j = i - 1         while j >= 0...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • can someone please tell me where did I do wrong and how I can fix this...

    can someone please tell me where did I do wrong and how I can fix this TU. . IVIL main.py Load default template... 1 # Read a list of strings from the user' 3 def square(x): return x*x nmin on input_string = input() 7 numbers= 11 8 for i in (str(input_string): numbers.append(i*2) 10 # Use list comprehension to cast them to ints 11 numbers = [int(i) for i in input_string.split()] 12 result = list (map(lambda x: x*x, numbers)) 13 for...

  • CAN SOMEONE PLEASE EXPLAN FO ME WHATS WRONG WITH MY CODE WHEN EVEN I RUN IT...

    CAN SOMEONE PLEASE EXPLAN FO ME WHATS WRONG WITH MY CODE WHEN EVEN I RUN IT IT GIVE ME THIS MASSAGE IM USING python BTW Traceback (most recent call last):                                                                                                                                                 File "../resource/asnlib/public/RUN.py", line 20, in <module>                                                                                                                      exec(source_code, dict())                                                                                                                                                      File "<string>", line 60, in <module>                                                                                                                                          NameError: name 'total_rough_sod' is not defined ) from math import pi length = float(input('Enter Course Length:')) width = float(input('Enter Course Width:')) def calculate_smooth_sod(width): grean_area_raduis= (width/2)/2 total_smooth_sod=2*pi*(grean_area_raduis**2) return total_smooth_sod def calculate_sand_trap_area(width): sand_trap_radius=(width/3)/2 sand_trap_area=pi*(sand_trap_radius**2) return sand_trap_area def calculate_rough_sod(length,...

  • Can someone please use layman's terms to explain to me the relationship between the notion of mathematical induction and recursion in computer science? I am struggling to understand the relationsh...

    Can someone please use layman's terms to explain to me the relationship between the notion of mathematical induction and recursion in computer science? I am struggling to understand the relationship

  • Practice: • function • loops • if condition • random Roll a dice many times, you...

    Practice: • function • loops • if condition • random Roll a dice many times, you will see that each face value will count of roughly 1/6 • write a function • roll a dice once, return value will be 1-6, • use your functin I call your function 6000 times • count how many times of face 1 • count how many times of face 2 • print out the numbers of total face 1, 2, ..., 6 you...

  • Can someone explain this mathematical step? How was the unit step function u[n-k-2] incorporated in the...

    Can someone explain this mathematical step? How was the unit step function u[n-k-2] incorporated in the sum? I'm having trouble seeing how this unit step function can be visualized and why it becomes the upper limit of the sum. n-k-2

  • Can someone please tell me what this means and how to do it? This is a...

    Can someone please tell me what this means and how to do it? This is a requirement for one of the classes I'm taking, it deals with the PYTHON programming language. The requirement is: "It must automatically copy the result to the operating system clipboard." The thing is that we aren't allowed to make the user download anything such as Pyperclip or Tkinter, so what am I supposed to do? Does it automatically get copied to the clipboard and this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT