     "metadata": {},
     "source": [
      "## Test Cases\n",
      "\n",
      "* 0 -> ''\n",
      "* 1 -> ()\n",
      "* 2 -> (()), ()()\n",
      "* 3 -> ((())), (()()), (())(), ()(()), ()()()"
     ]
    },
 
</s> remove     "* If no_of_left == 0 and no_of right == 0, add pair_string to result\n",
    "* Else \n",
    "    * If (no_left > 0), parentheses_util(no_left - 1, no_right, pair_string + '(', result)\n",
    "    * If (no_right > no_left), parentheses_util(no_left, no_right - 1, pair_string + ')', result)\n",
 </s> add     "\n",
    "Let `l` and `r` denote the number of left and right parentheses remaining at any given point. \n",
    "The algorithm makes use of the following conditions applied recursively:\n",
    "* Left braces can be inserted any time, as long as we do not exhaust them i.e. `l > 0`.\n",
    "* Right braces can be inserted, as long as the number of right braces remaining is greater than the left braces remaining i.e. `r > l`. Violation of the aforementioned condition produces an unbalanced string of parentheses.\n",
    "* If both left and right braces have been exhausted i.e. `l = 0 and r = 0`, then the resultant string produced is balanced.\n",
    "\n",
    "The algorithm can be rephrased as:\n",
    "* Base case: `l = 0 and r = 0`\n",
    "    - Add the string generated to the result set\n",
    "* Case 1: `l > 0`\n",
    "    - Add a left parenthesis to the parentheses string.\n",
    "    - Call parentheses_util(l - 1, r, new_string, result_set)\n",
    "* Case 2: `r > l`\n",
    "    - Add a right parenthesis to the parentheses string.\n",
    "    - Call parentheses_util(l, r - 1, new_string, result_set)\n", </s> remove     "* Time: O(4^n/n^(3/2)) "
 </s> add     "* Time: `O(4^n/n^(3/2))`. See [Catalan numbers](https://en.wikipedia.org/wiki/Catalan_number#Applications_in_combinatorics)\n",
    "* Space complexity: `O(n)` (Due to the implicit call stack storing a maximum of 2n function calls)" </s> remove    "execution_count": 5,
 </s> add    "execution_count": 1, </s> remove    "execution_count": 6,
 </s> add    "execution_count": 2,
    "* 0 -> ' '\n",
     "metadata": {},
     "source": [
      "## Test Cases\n",
      "\n",
    "* 0 -> ' '\n",
      "* 1 -> ()\n",
      "* 2 -> (()), ()()\n",
      "* 3 -> ((())), (()()), (())(), ()(()), ()()()"
     ]
    },
keep keep keep keep replace keep keep keep keep keep
 Updated n-pairs parentheses solution information 
recursion_dynamic/n_pairs_parentheses/n_pairs_parentheses_solution.ipynb