{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exam2b - Name Midterm 2 CS 20 Fall 2008 Short Answer/25...

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

View Full Document Right Arrow Icon
Name: ________________________ Midterm 2 CS 20 Fall 2008 Short Answer: _____/25 Output: _____/25 removeHead: _____/15 iterative countOccurrences _____/20 recursive countOccurrences _____/15 Total: _____/100
Image of page 1

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

View Full Document Right Arrow Icon
1) Write the base case and recursive case of each of the following problems (5 pts each): a) Calculating the value 4 x Base Case: Recursive Case: b) Counting the number of occurrences of an element in a linked list Base Case: Recursive Case: c) Your CD with initial balance b earns 4.5% interest per year. Calculate the value in year n. Base Case: Recursive Case: 2) 10 pts - Write the recursive method, in Java, to calculate the value 4 x public static int fourToTheX(int x) { } 3) (15 pts) (2-3-5-5) public static int mystery(int x) {
Image of page 2
if (x <= 1) return 3; else return (3 + mystery(x-1)); } What is the output for mystery(1)? What is the output for mystery(5)? In one sentence, describe what the previous method calculates: What is the computational complexity of the above method? Give an explanation. 4) 10 pts - What is the output of the following code?
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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