recursive algo. with memoization practice