This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+==================+=================+==================+ | |
| Solution | Time Complexity | Space Complexity | | |
+==================+=================+==================+ | |
| Backtracking | O(2^n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Bit Manipulation | (On*2^n) | O(1) | | |
+------------------+-----------------+------------------+ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void all_subset(vector<int>& A, vector<int>& subset, int index) | |
{ | |
print(subset); | |
for (int i = index; i < A.size(); i++) | |
{ | |
subset.push_back(A[i]); | |
all_subset(A, subset, i + 1); | |
subset.pop_back(); | |
} | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void all_subset(vector<int> a) | |
{ | |
int n=a.size(), c=0, i; | |
int total = pow(2, n); | |
for(c= 0; c< total; c++) | |
{ | |
for(i= 0; i< n; i++) | |
{ | |
if(c&(1<< i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void permutation(string str, int i) | |
{ | |
int n=str.size() | |
if (i == n - 1) | |
{ | |
cout << str << endl; | |
return; | |
} | |
for (int j = i; j < n; j++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void permutation(string S, int n, string res) | |
{ | |
if (n == 1) | |
{ | |
cout << res + S << endl; | |
return; | |
} | |
for (int i = 0; i < n; i++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Approaches | Time Complexity | Space Complexity | | |
+==================+=================+==================+ | |
| Reversing the lists and merging | O(n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Merging the list and reversing | O(n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Iterative Approach | (On) | O(1) | | |
+------------------+-----------------+------------------+ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Approaches | Time Complexity | Space Complexity | | |
+==================+=================+==================+ | |
| Depth First Search Approach | O(4^n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Breadth-First Search Approach | O(!n) | O(n) | | |
+------------------+-----------------+------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Approaches | Time Complexity | Space Complexity | | |
+==================+=================+========================+ | |
| Brute Force Approach | O(n^3) | O(1) | | |
+------------------+--------------------+---------------------+ | |
| Sliding Window Approach| O(n^2) | O(1) | | |
+------------------+--------------------+---------------------+ | |
| Hash-Table Approach | (On) | O(1) | | |
+------------------+-----------------+------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Approaches | Time Complexity |Space Complexity| | |
+==================+=================+==================+ | |
| Recursive Method | O(n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Iterative Method | O(n) | O(n) | | |
+------------------+-----------------+------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Approaches | Time Complexity |Space Complexity| | |
+==================+=================+==================+ | |
| Level Order Traversal| O(n) | O(n) | | |
+------------------+-----------------+------------------+ | |
| Recursive Function | O(n) | O(n) | | |
+------------------+-----------------+------------------+ |
OlderNewer