A classic recursive algorithm implementation