Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 1.87 KB

challenges.md

File metadata and controls

40 lines (34 loc) · 1.87 KB

Some good recursive coding challenges

the 3 basics of recursion - base case, general case, and proof that a base case will be reached. ...
Depth first, breadth first, reverse order...
guarded recursion

When you define a list as "any number of items where one comes after the other", you naturally think of iterative operations on lists -- you want to operate on that list with a "for" loop.

But when you define a list as "either empty, or an item followed by a list" then suddenly it becomes very natural to think recursively. The operation on the list becomes "solve the empty case, or solve the one-item case and recurse on the tail."

  • Factorial
  • Fibonacci
  • Towers of Hanoi
  • Converting to and from roman numerals
  • Traversing a file system
  • calculate the size of all files in a directory (including sub-directories).
  • Traversing the DOM
  • Traversing a binary tree
  • Reverse printing a linked list
  • Conway's Game of Life
  • Quicksort
  • Traversing a labyrinth
  • Knight's tour
  • N-queens
  • Divide and Conquer sorting is a great lead into recursion from crappy bubble sort.
  • generating HTML for threaded discussion boards
  • Writing code that plays simple board games
  • Naive implementation of a web spider
  • permutations of a word

References