<script>
const M = 8;
function
findEdges(arr, n, m)
{
let mat =
new
Array(1000);
for
(let i = 0; i < 1000; i++){
mat[i] =
new
Array(1000).fill(
'x'
);
}
for
(let i = 0; i < n; i++) {
for
(let j = i + 1; j < n; j++) {
for
(let k = 0; k < 2 * m; k += 2) {
if
(arr[i][k + 1] ==
'-'
|| arr[j][k + 1] ==
'-'
) {
continue
;
}
if
(arr[i][k + 1] != arr[j][k + 1]) {
mat[i][j] = 'v
';
mat[j][i] = '
v
';
break;
}
}
}
}
let nn = n;
// Loop over all node to find other non
// compatible edges
while (nn--) {
// Loop over every pair of nodes in
// the given formal language
for (let i = 0; i < n; i++) {
for (let j = i + 1; j < n; j++) {
let k = 0;
for (k = 0; k < m; k += 2) {
// If the output is
// not specified then
// leave edge unprocessed
if (arr[i][k + 1] == '
-
' || arr[j][k + 1] == '
-
') {
continue;
}
// If output is not equal
// then break as non-compatible
if (arr[i][k + 1] != arr[j][k + 1]) {
break;
}
}
if (k < m) {
continue;
}
for (k = 0; k < m; k += 2) {
// If next states are unspecified
// then continue
if (arr[i][k] == '
-
' || arr[j][k] == '
-
') {
continue;
}
// If the states are not equal
if (arr[i][k] != arr[j][k]) {
let x = arr[i][k].charCodeAt(0) - 65;
let y = arr[j][k].charCodeAt(0) - 65;
// If the dependent edge
// is not compatible then
// this edge is also not
// compatible
if (mat[x][y] == '
v
') {
mat[i][j] = '
v
';
mat[j][i] = '
v
';
break;
}
}
}
}
}
}
// Output all Non-compatible Edges
console.log("Not Compatible Edges ");
for (let i = 0; i < n; i++) {
for (let j = i + 1; j < n; j++) {
if (mat[i][j] == '
v
') {
document.write("(", String.fromCharCode(i + 65),",", String.fromCharCode(j + 65), ") ");
}
}
}
console.log();
// Output all Compatible Edges
console.log("Compatible Edges ");
for (let i = 0; i < n; i++) {
for (let j = i + 1; j < n; j++) {
if (mat[i][j] != '
v
') {
document.write("(", String.fromCharCode(i + 65),",", String.fromCharCode(j + 65), ") ");
}
}
}
}
// Driver Code
let n = 6, m = 4;
let arr = [ [ '
-
', '
-
', '
C
', '
1
', '
E
', '
1
', '
B
', '
1
' ],
[ '
E
', '
0
', '
-
', '
-
', '
-
', '
-
', '
-
', '
-
' ],
[ '
F
', '
0
', '
F
', '
1
', '
-
', '
-
', '
-
', '
-
' ],
[ '
-
', '
-
', '
-
', '
-
', '
B
', '
1
', '
-
', '
-
' ],
[ '
-
', '
-
', '
F
', '
0
', '
A
', '
0
', '
D
', '
1
' ],
[ '
C
', '
0
', '
-
', '
-
', '
B
', '
0
', '
C
', '
1' ] ];
findEdges(arr, n, m);
</script>