w1d3 Flashcards
What’s a good way to visualize ruby’s modulo arithmetic?
Imagine a wheel with numbers written clockwise.
Count clockwise around the wheel for positive modulo.
Count counter-clockwise for negative modulo.
What’s a good way to get better debug information from an object?
Override the #inspect method
What’s a benefit to using a recursive solution over an iterative solution?
It can be easier to prove the correctness of a recursive algorithm.
High-level: quicksort
Recursive or iterative?
Choose a pivot.
Place all items less than the pivot to the left of the pivot.
Place all items greater than the pivot to the right of the pivot.
left = quicksort the left side right = quicksort the right side
Put these back in order:
left + pivot + right
(it’s recursive)
What’s a common cause of a StackOverflowError ?
Broken base case in recursive call
What’s the name of the highest level stack frame?
main
How do you refer to the smaller and smaller-sized problems that a recursive algorithm breaks its input into?
subproblems
What type of mathematical proof lends itself to recursion?
mathematical induction
What type of function lends itself to mathematical induction?
recursion
What’s mathematical induction in a nutshell?
If we can solve for a base case and we can solve for a general (or nth) case, then we have solved for all the cases.
List a 5 step process for programming recursively
Map out a recursive decomposition.
Identify the base case(s).
Think one level up from the base case.
Ensure that the return values from all cases are always of the same type.
Get a stack trace (debuggin).
How do you change the number of recursive calls Ruby will allow?
MAX_STACK_SIZE = num
What does MAX_STACK_SIZE let you control?
The maximum number of recursive calls allowed.
What are some semantic HTML5 containers?
0-2: 1 star 3-4: 2 star 5-6: 3 star 6-7: 4 star 8-9: 5 star
header fooder nav article aside figure figcaption section div
How does rails use the method_missing function?
dynamic finders such as
User.find_by_username_and_state(‘bob’, ‘california’)