solution3 - text long int catalan(int number catalan number...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
[WPI] [cs2223] [cs2223 text] [News] [Syllabus] [Exams] [Exam 3] cs2223, D97/98 Exam 3 Solution Question 3.1 This is Newton's method for finding the square root of a number. It starts when the error is about n and ends when the error is 2 -20 and the error is roughly halved during each step. Thus the order is approximately: This is verified in the attached script . Note when n is a perfect square that the approximately 20 additional steps are not performed. Question 3.2 The function calls itself recursively twice with n-1 and it performs two subtractions and two additions. The recurrence relation for the number of additions or subtractions is: The solution is: When n = 10 50 , the answer is a very large number: The attached script shows that this function produces the correct answer when n =20. Question 3.3 Use the algorithm from Section 8.1.1 of the text to calculate the binomial coefficient. The attached script shows that this function produces the correct answers - compare with the table in Section 8.6 of the
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: text . long int catalan(int number) // catalan number { // uses pascal's triange; assume 0 <= n <= 20 long int triangle[39][39] = {0}; // it never gets bigger than this int n, k; // see section 8.1.1 of the text for (n = 0; n < 39; n++) triangle[n][0] = 1; for (n = 1; n < 39; n++) // fill in pascal's triangle for (k = 1; k <= n; k++) triangle[n][k] = triangle[n-1][k-1] + triangle[n-1] [k]; return triangle[2*number - 2][number - 1] / number; } // end catalan() The grading criteria are available. These are subject to interpretation by the grader. As we stated in class, our primary goal in the grading of these exams is consistency. If your intrepretation differs from the grader's and the grader has applied her/his criteria uniformly, then the grader's interpretation will prevail. [cs2223 text] [News] [Syllabus] [Exams] [Exam 3] Contents ©1994-1998, Norman Wittels Updated 17Apr98...
View Full Document

{[ 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