diff --git a/Permutations.cpp b/Permutations.cpp index 8b61c3f..75fa7c0 100644 --- a/Permutations.cpp +++ b/Permutations.cpp @@ -2,63 +2,31 @@ using namespace std; -// Checking whether a map has all the values equal to 0 in its key-value mapping -bool isEmpty(mapm) -{ - for(auto y=m.begin();y!=m.end();y++) - { - if(y->second==0) - continue; - - else - return false; - } - - return true; -} -void perm(mapfreq,string r="") -{ - // Checking if all the letters have been exhausted and no further Permutations can be formed - if(isEmpty(freq)) - { - cout<second==0) - continue; - +// Time Complexity:O(N!); - // Making a duplicate Map containing the frequency of all the letters as it is in the present map but the particular character,pointed in this specific Iteration of the Loop has Frequency less by 1 than found in the original map - maptemp; - - for(auto y=freq.begin();y!=freq.end();y++) - temp[y->first]=y->second; - - temp[p->first]--; +// Space Complexity:O(N) + +// N=(length of string) - // Recursively calling the function with the newly formed map - perm(temp,r+p->first); - } -} - -// Driver Code to test the Function -int main() { +void print_permutation(string permutation,string result){ - string s="abaaa"; - mapm; + if(permutation.size()==0)cout<