-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Create connected-components.md #269
Conversation
Added a tutorial for connected components in a graph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look at the checklist first as well as other tutorials for reference.
I have made the required changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read it again.
any update? |
@wingkwong I have made changes to make it similar to other tutorials. Also I or someone else will need to write the solution for 0547 (Number of provinces). Should I raise an issue for that as well? |
@adityabisht02 Please look at the latest checklist and this tutorial |
@wingkwong I have made some changes according to the tutorial and checklist u referred ,it should be good now |
In a graph, sometimes all nodes might not be connected with each other. Let's take an example of a graph with 5 nodes- | ||
|
||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer a better image
<TutorialAuthors names="Aditya Bisht"/> | ||
|
||
## Overview | ||
In a graph, sometimes all nodes might not be connected with each other. Let's take an example of a graph with 5 nodes- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take an example of a graph with 5 nodes.
3. If you are unable to reach a particular node or a group of nodes, then that group of nodes might be a different connected component. | ||
|
||
## How to find connected components? | ||
1. Let's an adjacency list based graph is given. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create an adjacency list based on the given graph
## How to find connected components? | ||
1. Let's an adjacency list based graph is given. | ||
2. Traverse the adjacency list and for every node do a BFS or DFS on the node and mark all the nodes you visit in this way as visited. | ||
3. While traversing the list do not do BFS on the nodes which have already been visited. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or DFS
Return the total number of provinces. | ||
``` | ||
|
||
Here, the given graph is in the form of an adjacency list. When we perform bfs/dfs starting from one particular node, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also show a DFS solution
<SolutionAuthor name="@adityabisht02"/> | ||
|
||
```Java | ||
class Solution { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format the code following K&R Coding style
``` | ||
</TabItem> | ||
</Tabs> | ||
The time complexity of the above solution is O(n) where n is the number of elements in the isConnected list. We have also used an array with size equal to the number of nodes in the graph (not the number of elements in isConnected). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- it's not O(N) ...
- missing space complexity
- apply LaTex on them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply LaTex where ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already stated in the checklist.
Make sure you've applied LaTex for variables, formulas and time / space complexity instead of using backticks
Closing due to inactivity. |
Added a tutorial for connected components in a graph
Change Summary
Issue #107
Checklist
Ideally all of them should be checked. If you haven't fulfilled the below requirements or even delete the entire checklist, your PR won't be reviewed.
General
<Tabs/>
)Below is a C++ example. You can include multiple langs using
<TabItem/>
if necessary## Approach 1: Two Pointers
.For Tutorial Articles
solutionLink
blank.