Here is my approach. Do DFS and check in stack whether the new node is already in the Stack or not.public static boolean isCyclicDFS(int[][] adjMat) {        int len = adjMat.length;        boolean[] isVisited = new boolean[len];        for(int i =0; i<len; i++) {            isVisited[i] = false;        }        Stack s = new Stack<>();        s.add(0);        while(!s.isEmpty()) {            int current = (int) s.pop();            System.out.println(current);            isVisited[current] = true;            for(int i =0; i<len; i++) {                if(adjMat[current][i] ==1 && isVisited[i] == false) {                    if(s.contains(i)) {                        return false;                    }                    s.push(i);                    break;                }            }        }        return true;    }Kindly suggest if any improvement/correction.
Check if the undirected graph is cyclic
java;interview questions;graph