q10 sol3 - CSCI.1100 Computer Science I Quiz 10 Monday...

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

View Full Document Right Arrow Icon
CSCI.1100 Computer Science I Quiz 10 Monday November 23, 2009 Closed book, closed notes, no computers or calculators of any kind. Name: RCS login: Circle your lab section: (01 MTh 10:00) (02 MTh 12:00) (03 MTh 2:00) (04 MTh 4:00) (05 MTh 6:00) (06 MTh 10:00) (07 TF 10:00) (08 TF 12:00) (09 MTh 12:00) (10 TF 2:00) (11 MTh 4:00) 1. The Fibonacci sequence is defined as follows: If (n = 0) then fib (n) = 0 If (n = 1) then fib (n) = 1 Otherwise fib(n) = fib (n – 1) + fib (n – 2) a) Write a recursive function to compute the Fibanacci number for any positive integer. (4 points) int fib (int n) { if (n == 0) return 0; else if (n == 1) return 1; else return (fib (n – 1) + fib (n – 2); } 2 point for simple cases 2 points for simplification case
Image of page 1

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

View Full Document Right Arrow Icon
2. Complete the following recursive function to find the largest number in a list of positive numbers or -1 if the list is empty. The code must be recursive [5 points]. int largest (vector < int > input) { int largest (vector <int> input) { if (input.size () == 0) return -1; else { int next = input[input.size() – 1]; input.pop_back(); int current_large = largest (input); if (next > current_large) return next; else
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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