Hasty Briefsbeta

Bilingual

Beej's Bit Bucket

a day ago
  • Recursion occurs when a function calls itself, which can cause a stack overflow if infinite.
  • Recursive calls can be made conditional to stop recursion, e.g., by checking a parameter value.
  • Tail recursion happens when the recursive call is the last operation; it can be optimized into a loop.
  • Recursive solutions require identifying self-similar subproblems, like in factorial (n! = n × (n-1)!).
  • Base cases (e.g., factorial(0) = 1) are essential to stop recursion.
  • Recursion can traverse trees (pre-order, in-order, post-order) and perform flood fill by coloring pixels and recursing on neighbors.
  • Quicksort recursively partitions sets around a pivot to sort them.