# Exam2 - 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 3 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 3.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 3 x public static int threeToTheX(int x) { } 3) (15 pts) (2-3-5-5) public static int mystery(int x) {
if (x <= 1) return 5; else return (5 + 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 ]}

### Page1 / 7

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online