DP | C++ | Recursion->Memoization->Tabulation | Well commented
Recursive Solution [ Time-Complexity = O(n^2),  Space-Complexity = O(n) ]\n\t\n \n\tint count(int i, int n, string &vowels){\n\n\t\t\tif(n==0) return 1; // if a
**Recursive Solution** **[ Time-Complexity = O(n^2),  Space-Complexity = O(n) ]**\n\t\n ```\n\tint count(int i, int n, string &vowels){\n\n\t\t\tif(n==0) return 1; // if a string of length n is formed\n\n\t\t\tif(i>=5) return 0; // if i exceeds the length of vowels\n\n\t\t\tint pick, notPick;\n\t\t\t// pick i.e. pick this alphabet\n\t\t\tpick= count(i, n-1, vowels);\n\t\t\t// notPick i.e. skip this alphabet\n\t\t\tnotPick= count(i+1, n, vowels);\n\n\t\t\treturn pick + notPick;\n\t}\n\n\tint countVowelStrings(int n) {\n\t\t string vowels= "aeiou"; // all vowels in lexicographically sorted order\n\t\t return count(0, n, vowels);\n\t}\n\t\n```\n\t\n**Memoization** **[ Time-Complexity = O(4 * n),  Space-Complexity = O(5 * n) + O(n) ]**\n\n\n ```\n\tint count(int i, int n, string &vowels, vector<vector<int>> &dp){\n\n\t\t  if(n==0) return 1; // if a string of length n is formed\n\n\t\t  if(i>=5) return 0; // if i exceeds the length of vowels\n\n\t\t  if(dp[i][n]!=-1) return dp[i][n]; // check if dp already contains the answer\n\n\t\t  int pick, notPick;\n\t\t  // pick i.e. pick this alphabet\n\t\t  pick= count(i, n-1, vowels, dp);\n\t\t  // notPick i.e. skip this alphabet\n\t\t  notPick= count(i+1, n, vowels, dp);\n\n\t\t  return dp[i][n]= pick + notPick; // store the value in dp\n\t}\n\n\tint countVowelStrings(int n) {\n\t\t string vowels= "aeiou"; // all vowels in lexicographically sorted order\n\t\t vector<vector<int>> dp(5, vector<int>(n+1, -1)); // declare dp vector\n\t\t return count(0, n, vowels, dp);\n\t}\n```\n\t\n**Tabulation** **[ Time-Complexity = O(4 * n),  Space-Complexity = O(5 * n) ]**\n\n```\n\tint countVowelStrings(int n) {\n\n\t\tstring vowels= "aeiou"; // all vowels in lexicographically sorted order\n\n\t\tvector<vector<int>> dp(5, vector<int>(n+1)); // dp vector\n\n\t\t// base-case\n\t\tfor(int i=0; i<5; ++i) dp[i][0]= 1; // if n==0 return 1\n\n\t\t// tabulation\n\t\tfor(int i=4; i>=0; --i){\n\t\t  for(int j=1; j<=n; ++j){\n\t\t\tint pick= 0, notPick= 0;\n\t\t\t// pick i.e. pick this alphabet\n\t\t\tpick= dp[i][j-1];\n\t\t\t// notPick i.e. skip this alphabet\n\t\t\tif(i<4) notPick= dp[i+1][j];\n\n\t\t\tdp[i][j]= pick+notPick;\n\t\t  }\n\t\t}\n\n\t\treturn dp[0][n]; // return all strings possible starting from 0 index and of n length\n\t}\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']