Skip to content

Commit

Permalink
updating files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanashii76 authored Feb 28, 2024
1 parent ab8511e commit 85c8f8a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
41 changes: 41 additions & 0 deletions theory/backtracking/brackets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <string>

void generateBrackets(std::string output, int n, int open, int close, int i) {

// base case
if(i==2*n) {
std::cout << output << std::endl;
return;
}

// open
if(open<n) {
generateBrackets(output + '(',n,open+1,close,i+1);
}

//closing
if(close<open) {
generateBrackets(output + ')',n,open,close+1,i+1);
}


}



int main(){

std::string output;
int n;
std::cin >> n;

generateBrackets(output, n, 0,0,0);

}






24 changes: 24 additions & 0 deletions theory/backtracking/findingSubsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ void findSubsets(char *input, char *output, int i, int j) {
}


void substringsBit(std::string s1, int i) {

int index = 0;
while(i != 0) {
int last_bit=i&1;
if(last_bit)
std::cout << s1[index];
index++;
i = 1>>1;
}

std::cout << std::endl;

}

void generateSubstring(std::string s1) {

for(int i = 0; i < (1<<s1.length());++i)
substringsBit(s1, i);
return;

}




int main(){
Expand Down

0 comments on commit 85c8f8a

Please sign in to comment.