Exam2 - Name: _ Midterm 2 CS 20 Fall 2008 Short Answer:...

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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) {
Background image of page 2
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?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

Exam2 - Name: _ Midterm 2 CS 20 Fall 2008 Short Answer:...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online