Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kruskal Algorithm, removal of Java #561

Merged
merged 5 commits into from
Oct 31, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ else
## Implementation:

* [C](#c)
* [C++](#cpp)
* [Python](#python)
* [C#](#cSharp)

Expand Down Expand Up @@ -127,64 +126,6 @@ int main() {
```


## C++

```cpp
// C++ Program for longest common subsequence

#include <iostream>
using namespace std;

void lcsAlgo(char *S1, char *S2, int m, int n) {
int LCS_table[m + 1][n + 1];


// Building the mtrix in bottom-up way
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 || j == 0)
LCS_table[i][j] = 0;
else if (S1[i - 1] == S2[j - 1])
LCS_table[i][j] = LCS_table[i - 1][j - 1] + 1;
else
LCS_table[i][j] = max(LCS_table[i - 1][j], LCS_table[i][j - 1]);
}
}

int index = LCS_table[m][n];
char lcsAlgo[index + 1];
lcsAlgo[index] = '\0';

int i = m, j = n;
while (i > 0 && j > 0) {
if (S1[i - 1] == S2[j - 1]) {
lcsAlgo[index - 1] = S1[i - 1];
i--;
j--;
index--;
}

else if (LCS_table[i - 1][j] > LCS_table[i][j - 1])
i--;
else
j--;
}

// Printing the sub sequences
cout << "S1 : " << S1 << "\nS2 : " << S2 << "\nLCS: " << lcsAlgo << "\n";
}

int main() {
char S1[] = "ACDABCD";
char S2[] = "ADBCA";
int m = strlen(S1);
int n = strlen(S2);

lcsAlgo(S1, S2, m, n);
}

```

## Python

```python
Expand Down