1/14
Looks like no tags are added yet.
What is the anatomy of defining a method in Java?
void <name>() {
<statements> — ( method’s body )
}
How do you call a method?
<name>()
What are some aspects in terms of statement organization?
Methods can group statements
Hide local variables and implementation
Hidden == not changeable/visible by the outside code
Why is hiding information good?
Reduces dependencies in the program between parts of the program
Decrease complexity
Increase flexibility
What does “double” from double method (int parameter ) mean
It is the return type
What does “int parameter” from double method (int parameter ) mean
It is the passed parameter that you can pass upon calling
Parameter is hidden from outside code
What is difference between methods and functions?
Functions are methods with a return value
What does void mean
The function returns nothing
Where are other methods declared
They are declared at class level not inside other methods
What is the scope of parameters and variables of a method?
They are not visible from the outside code
What is the general idea of recursion?
Divide the problem into:
Base cases where method returns x,1,false etc
And Reduction to the same problem but of smaller size
What does mutual recursion mean?
The recursion is not a direct call but rather via other method.
f calls g and g calls f
Which is the situation where you use recursion?
When a recursive definition or recurrence relation is known
Which is faster recursion or iteration
Iteration
What are typical errors in recursion?
no or incomplete base cases
not always reduction in size
too many steps in size reduction part