Recursion


Recursion with Memoization

In order to emove the redundancy, we use memoization to store the results which have been calculated earlier.

Memoization is an easy method to track previously solved solutions. It can be used in both bottom up or top down methods.


[Medium] No.494 Target Sum

Approach1: Basic Recursion (Brute Force)

Time Complexity: O(2^N), where N is the number of nodes in the given list.

Space Complexity: O(N), the depth of recursion tree would be and need to have N times call stacks.

Approach2: Recursion with Memoization

Time Complexity: O(l * N), where N is the number of element in the given list and l is the numbers of each element in the memo vector.

Space Complexity: O(l * N), the memo vector size.