homework7 - Zhaoyang Dai 22C:016:A06 ID:00719596 1 Copy and...

Info icon This preview shows page 1. Sign up to view the full content.

Zhaoyang Dai 22C:016:A06 ID:00719596 1. Copy and save the Python program below in a file called slowListBuild.py. (a) Run slowListBuild.py and report the amount of time (in seconds) that the program took to complete. Answer: The result is 120.556999922 seconds. (b) Suppose you double the value of n from 500,000 to a million. Do you think the program will take roughly twice as much time (yes or no)? Explain your answer in 1-2 sentences. Answer: No, this program will read the list every time when it execute the for-loop, as the length of the list get longer, the program will need more time to read the list. (c) Rewrite the program using append rather than insert and report the time the program took. Make sure your new program does exactly what the original did, i.e., it should build the same list as before. Call your new program fasterListBuild.py and submit it as part of your solution. Answer: It takes 0.18700003624 seconds. (d) Explain in 1-2 sentences why there is such a big difference in running times of the two versions of the programs.
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '13
  • MichaelColbert
  • Names of large numbers, 0.18700003624 seconds

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern