Skip to content

Instantly share code, notes, and snippets.

@cqfd
Last active December 25, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cqfd/7045316 to your computer and use it in GitHub Desktop.
Save cqfd/7045316 to your computer and use it in GitHub Desktop.
Recursion!
  1. Write a recursive function to compute the length of a list.
  2. Write a recursive function to compute the sum of a list of numbers.
  3. Write a recursive function to compute the sum of a binary tree of numbers.
  4. Write a recursive implementation of the map function.
  5. Write a recursive implementation of the filter function.
  6. Write a recursive function that inserts an element in the right place into a linked list. The function should return a new linked list rather than mutate the original list.
  7. The change counting problem from SICP: http://mitpress.mit.edu/sicp/full-text/sicp/book/node16.html
  8. Write a recursive function that enumerates the nodes of a tree in depth-first {pre|in|post} order.
  9. Write a recursive function that computes the "power set" of a set.
  10. Write a recursive function that computes the number of ways of distinct k-element subsets of a set with n elements. In other words, "n choose k".
  11. Explicitly compute (rather than just counting) all k-element subsets of a set.
  12. Write a recursive function that generates all possible partitions of a set.
  13. Write a recursive function that calculates the minimax "value" of a board in Tic-Tac-Toe :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment