├── prime-number-sieve-algorithm.cpp ├── longest-decreasing-subsequence-o(n2).cpp ├── longest-increasing-subsequence-o(n2).cpp └── depth-first-search-algorithm.cpp /prime-number-sieve-algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define M 1234567 5 | using namespace std; 6 | 7 | int prime[M+1]={0}; 8 | vectorprimeNumber; 9 | 10 | void primeGen(){ 11 | for(int i=2; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin >> n; 9 | int data[n]; 10 | for(int i=0; i> data[i]; 12 | } 13 | // count longest sequence 14 | int lis[n]={1}; 15 | for(int i=0; idata[i]){ 18 | if(lis[i] 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin >> n; 9 | int data[n]; 10 | for(int i=0; i> data[i]; 12 | } 13 | // count longest sequence 14 | int lis[n]={1}; 15 | for(int i=0; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int vertex; // vertex / node of the graph 8 | int edge; // edge / connection of the graph 9 | vectorsequence; 10 | int startingNode; // starting node to traverse the graph 11 | vectorgraph[100]; // graph to traverse 12 | bool visited[100] = {false}; // checking the node has been visited or not 13 | 14 | void inputGraphData(int a, int b){ 15 | graph[a].push_back(b); 16 | } 17 | 18 | void createGraph(){ 19 | int a; // source 20 | int b; // destination 21 | while(edge--){ 22 | cin >> a >> b; 23 | inputGraphData(a, b); 24 | } 25 | } 26 | 27 | void dfs(int startingNode){ 28 | visited[startingNode]=true; 29 | sequence.push_back(startingNode); 30 | for(int i=0; i> vertex; // taking the number of node 57 | cin >> edge; // taking the number of connection 58 | createGraph(); 59 | //displayGraph(); // just for checking that 2d vector is working 60 | //cin >> startingNode; 61 | dfs(1); 62 | //cout << sequence.size() << endl; 63 | displaySequence(); 64 | //for(int i=0; i