add recursive algorithm