1. Homepage
  2. Programming
  3. [2022] CPSC 110 Introdunction to Computer Science - Assignment 7: Running Sum and Nilakantha Series

[2022] CPSC 110 Introdunction to Computer Science - Assignment 7: Running Sum and Nilakantha Series

Engage in a Conversation
CPSC 110Intro to Computer ScienceRunning SumNilakantha SeriesUMW

Assignment 7 CourseNana.COM

  1. All assignments will be submitted through Canvas. If you submit multiple times, the most recent submission will be graded.
  2. Please review the collage’s plagiarism policies. As a general rule, copy/paste should never be used for any code. Ever. You may discuss topics with other students and reference online materials, but the final assignment must be written by the student. If you reference materials/people besides the textbook/instructor then cite this in a file contributions.txt. Full citations are not necessary, a bullet point list of the materials/people that you references is suitable.
  3. Code will be graded for functionality as well as quality. This means code that should be easy to read with descriptive variable names and appropriate comments.
  4. Code that cannot run successively in Python 3 will receive a zero. Make sure you are using the correct python verion and allow yourself enough time for thorough testing.
  5. At the start of each assignment will be a list of the required files for submission. All files should be compressed in one zip folder named yourname ASSIGN7 CPSC110.
    For example:
    JOCELYNMINNS ASSIGN7 CPSC110


CourseNana.COM

Assignment 7 Instructions: CourseNana.COM

       Total Points: 30 CourseNana.COM

       Due: July 6, 2022, 11:59pm CourseNana.COM

       Requiered files: CourseNana.COM

1. timing.py
2. nilakantha.py
3. assign7.txt
4. contributions.txt CourseNana.COM

1 Running Sum [15 points] CourseNana.COM

Below are two versions of the same function: running sum. They will both produce the same output. CourseNana.COM

1      def running_sum_v1(aList): bList = aList[:]
length = len(aList)
for index in range(length): CourseNana.COM

2       bList[index] = bList[index] + sum(aList[:index]) CourseNana.COM

3     return bList CourseNana.COM

4        CourseNana.COM

5      def running_sum_v2(aList): bList = aList[:]
length = len(aList)
for index in range(1,length): CourseNana.COM

6   bList[index] = bList[index] + bList[index-1] CourseNana.COM

7      return bList CourseNana.COM

We are told by the creators of Python that: CourseNana.COM

len(list) has time T(n) = 1
sum(list) has time T(n) = n
CourseNana.COM

1.1 Big-O of the functions CourseNana.COM

What is the Big-O of running sum v1 and running sum v2? Which function is better? Write your answer in a file assign7.txt CourseNana.COM

1.2 Timing the functions CourseNana.COM

We saw an example in the slides about timing a function. Write a main function that calls each function above, times how long they take and prints the result. You should time the function with each a list of size 100, a list of size 1,000 and a list of size 10,000 then prints the times for each test. Save your code in timing.py CourseNana.COM

Note that to get a list of size n, you can use: CourseNana.COM

aList = list(range(n)) CourseNana.COM

For each length 100, 1000, and 10000 what times did you get from running sum v1 and running sum v2? Do these numbers makes sense given the answer in the previous part? Write your answer in a file assign7.txt CourseNana.COM

2 Nilakantha Series [15 points] CourseNana.COM

There are many mathematical formulas to determine the value of PI. The one we are focusing on today is the Nilakantha Series. This infinite series is used to estimate the value of Pi. It can be defined as: CourseNana.COM


Below is a Python function that that calculates the first
n terms of the Nilakantha Series. CourseNana.COM

1      def nilakanthaSeries(terms): CourseNana.COM

2     CourseNana.COM

3     for counter in range(terms): CourseNana.COM

4       result = 3 CourseNana.COM

5       denom = 2 CourseNana.COM

6       for n in range(counter): CourseNana.COM

7      result = result + (-1.0)**(n)*4.0/(denom*(denom+1)*(denom+2)) CourseNana.COM

8         denom = denom + 2 CourseNana.COM

9       pi = result CourseNana.COM

10   return pi CourseNana.COM

However, this code can be slow. CourseNana.COM

2.1 Orignal Code CourseNana.COM

What is the Big-O of this function? Write your answer in a file assign7.txt CourseNana.COM

2.2 Fixing Code CourseNana.COM

Improve this code so that it will be faster. Put your new version of the function in the file nilakantha.py CourseNana.COM

2.3 Fixed Code CourseNana.COM

What is the Big-O of the new function? Write your answer in a file assign7.txt CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CPSC 110代写,Intro to Computer Science代写,Running Sum代写,Nilakantha Series代写,UMW代写,CPSC 110代编,Intro to Computer Science代编,Running Sum代编,Nilakantha Series代编,UMW代编,CPSC 110代考,Intro to Computer Science代考,Running Sum代考,Nilakantha Series代考,UMW代考,CPSC 110help,Intro to Computer Sciencehelp,Running Sumhelp,Nilakantha Serieshelp,UMWhelp,CPSC 110作业代写,Intro to Computer Science作业代写,Running Sum作业代写,Nilakantha Series作业代写,UMW作业代写,CPSC 110编程代写,Intro to Computer Science编程代写,Running Sum编程代写,Nilakantha Series编程代写,UMW编程代写,CPSC 110programming help,Intro to Computer Scienceprogramming help,Running Sumprogramming help,Nilakantha Seriesprogramming help,UMWprogramming help,CPSC 110assignment help,Intro to Computer Scienceassignment help,Running Sumassignment help,Nilakantha Seriesassignment help,UMWassignment help,CPSC 110solution,Intro to Computer Sciencesolution,Running Sumsolution,Nilakantha Seriessolution,UMWsolution,