1/43
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is recursive thinking
The expectation of finding simpler versions of a large problem during the design process.
What is recursion in programming
When a method activates itself to solve a problem.
What is a recursive method
A method that calls itself to solve smaller versions of a problem.
What is the stopping case (base case)
A case where the problem is simple enough to be solved without recursion.
What is a recursive call
A method activating itself to solve a simpler instance of the same problem.
What happens if there is no stopping case
The recursion will not terminate and may cause a StackOverflowError.
How are digits extracted in writeVertical
Using number/10 for all but last digit and number % 10 for the last digit.
What does number/10 represent in recursion
A simpler version of the original number with one fewer digit.
What does number % 10 represent
The last digit of the number.
What is the purpose of writeVertical
To print the digits of a non-negative integer vertically.
How does recursion handle negative numbers in superWriteVertical
It prints a negative sign and calls itself with -number.
What is an activation record
A memory block storing parameters, local variables, and return location for a method.
What is the execution stack
A stack data structure that stores activation records during method calls.
What happens when a method is called
Execution pauses, information is saved, and a new activation record is created.
What happens when a method finishes
Its activation record is removed and execution returns to the previous method.
Why must recursive calls eventually stop
To prevent infinite recursion and program failure.
What is infinite recursion
When recursive calls never reach a stopping case.
What error occurs from infinite recursion
StackOverflowError.
What is a fractal
An object that exhibits similarity under magnification.
What is a random fractal
A fractal generated using random variations.
How is the midpoint calculated in randomFractal
midX = (leftX + rightX)/2 and midY = (leftY + rightY)/2.
What is delta in randomFractal
A random vertical shift applied to the midpoint.
What is the purpose of recursive calls in randomFractal
To generate fractals for smaller line segments.
What is the stopping condition in randomFractal
When the horizontal distance is small enough, draw a line.
What does drawLine do
Draws a line between two points on a Graphics object.
What is the role of the Graphics object
It allows drawing images using pixel coordinates.
What is the purpose of traverseMaze
To guide a user through a maze and back out.
What is the stopping case in traverseMaze
When the tapestry is found.
What is a dead end in the maze
A direction blocked by a wall or already visited.
Why does traverseMaze avoid revisiting spots
To prevent infinite loops.
What is backtracking
Returning to a previous point after exploring a path that failed.
What is exhaustive search
Trying all possible paths to find a goal.
What is the role of marking in maze traversal
To track visited locations and avoid repetition.
What does the inquire method do
Asks a yes/no question and returns true or false.
How does deadend determine a blocked path
By checking for a wall or a previously visited location.
What is the goal of the Teddy Bear game
To reach a target number of bears within a limited number of steps.
What are the two moves in the Teddy Bear game
Add increment bears or halve the bears if even.
What is the stopping case in bears method
When initial equals goal.
What happens when no steps remain in bears
The method returns false.
How does recursion help solve the bears problem
By exploring possible moves as smaller subproblems.
What is the purpose of the power method
To compute x raised to the power n.
How are negative exponents handled in power
By returning 1/power(x, -n).
What is the base case for exponentiation
When n equals 0, the result is 1.