BFS | DFS | C++ | Easy to understand code
Intuition\nWe have to find number of connected components in the graph.\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nNormal DFS/
# Intuition\nWe have to find number of connected components in the graph.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nNormal DFS/BFS traversals, number of times the traversal is done is the number of provinces.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```BFS []\nclass Solution {\npublic:\n\nvoid bfs(int node, vector<int> &vis, vector<int> adj[]){\n    queue<int> q;\n        q.push(node);\n        vis[node]=1;\n        while(!q.empty()){\n            int node=q.front();\n            q.pop();\n            for(auto x:adj[node]){\n                if(!vis[x]){\n                    vis[x]=1;\n                    q.push(x);\n                }\n            }\n        }\n}\n\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        int n=isConnected.size();\n        vector<int> adj[n];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(i==j) continue;\n                if(isConnected[i][j]==1){\n                    adj[i].push_back(j);\n                    adj[j].push_back(i);\n                }\n            }\n        }\n        int count=0;\n        vector<int> vis(n,0);\n        for(int i=0;i<n;i++){\n            if(!vis[i]){\n                bfs(i,vis,adj);\n                count++;\n            }\n        }\n        return count;\n    }\n};\n```\n```DFS []\nclass Solution {\npublic:\n\nvoid dfs(int node, vector<int> &vis, vector<int> adj[]){\n    vis[node]=1;\n    for(auto x:adj[node]){\n        if(!vis[x]) dfs(x,vis,adj);\n    }\n}\n\n    int findCircleNum(vector<vector<int>>& isConnected) {\n        int n=isConnected.size();\n        vector<int> adj[n];\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(i==j) continue;\n                if(isConnected[i][j]==1){\n                    adj[i].push_back(j);\n                    adj[j].push_back(i);\n                }\n            }\n        }\n        int count=0;\n        vector<int> vis(n,0);\n        for(int i=0;i<n;i++){\n            if(!vis[i]){\n                dfs(i,vis,adj);\n                count++;\n            }\n        }\n        return count;\n    }\n};\n```\n# ***Upvote if it helped!***\n`
['C++']