{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exam2b

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

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

Name: ________________________ Midterm 2 CS 20 Fall 2008 Short Answer: _____/25 Output: _____/25 removeHead: _____/15 iterative countOccurrences _____/20 recursive countOccurrences _____/15 Total: _____/100

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

View Full Document
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) {
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?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern