1 of 19

Welcome to CS61B!

Section 107

2 of 19

Agenda

  • Announcements
    • Resources
  • Summer Reflections
  • HW0
  • Intro to Java

3 of 19

Announcements

  • HW0 due 11:59pm on Friday, 9/1
  • Lab1 due 11:59PM on Tuesday, 8/29
  • If you’re still having setup issues, talk to me after class!

Names*

4 of 19

Resources

Java Visualizer

Java docs

Stack Overflow

You are never the first person to have a question! You just need to find the answer to when it was asked previously.

5 of 19

Summer Reflections

6 of 19

7 of 19

8 of 19

HW0

9 of 19

HW0

  • Public class names must match their respective file names
    • If class is declared non-public, no need to match file names
  • Boolean checking with for loops
    • Put true condition inside of loops
    • Put false condition after all loops have ended
  • Remember to tag and push!

10 of 19

Intro to Java

11 of 19

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?

Visualization

12 of 19

While Loops

_________________________________________________________________________

What is each line doing here?

Based on the initial value of x, how many times will this loop run?

13 of 19

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?

14 of 19

Recursive Fib

_________________________________________________________________________

Fibonacci Formula: FN= FN - 1 + FN - 2 F0 = 0, F1 = 1

What is our base case? What about our recursive case?

15 of 19

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?

16 of 19

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?

17 of 19

mystery

18 of 19

mystery2

19 of 19

mystery cont.

  • What does mystery return if inputArray is the array {3, 0, 4, 6, 3} and k is 2?
    • What do the variables x, answer and index represent? When are they modified?
    • What happens if the “if” condition is true?
  • Describe, in English, what mystery returns.
  • Extra for experts: What does mystery2 return if inputArray is the array {3, 0, 4, 6, 3} and k is 2? Then, describe in plain English, what mystery2 does to the array.
    • What will targetIndex be at each iteration?
    • What happens to inputArray at each iteration?

Java Visualizer