Welcome to CS61B!
Section 107
Agenda
Announcements
Names*
Resources
You are never the first person to have a question! You just need to find the answer to when it was asked previously.
Summer Reflections
HW0
HW0
Intro to Java
Variable Declaration and Initialization
_________________________________________________________________________
How do we know the types of a variable? How do we know the value of a variable?
Which side of the “=” sign is declaration, and which side is initialization?
What is the third line doing? Specifically, what special function is it calling?
While Loops
_________________________________________________________________________
What is each line doing here?
Based on the initial value of x, how many times will this loop run?
For Loops
_________________________________________________________________________
What is each line doing here?
What is phrases? How do we access its elements?
How many times does the for loop run?
Does i increase by 1 before or after the loop body?
Recursive Fib
_________________________________________________________________________
Fibonacci Formula: FN= FN - 1 + FN - 2 F0 = 0, F1 = 1
What is our base case? What about our recursive case?
Non Redundant (Iterative) Fib
_________________________________________________________________________
Recursive solution builds from the top down. Can we build from the bottom up?
Suppose we had 2 variables to represent the previous 2 fibonacci terms. What would their starting values be?
How would their values change at each iteration?
How many times would we need to change their values? How would we know we are done?
What do we return?
Shorter, Non-Redundant Fib
_________________________________________________________________________
Based on our parameters, what is our base case and what do we return in that case?
For our recursive case, what can we do to avoid extra variables?
Hint: How do the parameters to our function change?
mystery
mystery2
mystery cont.