1

So I'm making this code in C++ which is supposed to tell which elements from a connected graph can be removed so the graph stays connected, but I don't even know where to start. I was thinking of making a copy of the initial graph and try to remove an element at a time and then check if the remaining graph is still connected(putting each element back after I'm done of course). However, this would take WAY too much time. I'm sure there's some kind of principle or algorithm I don't know, but I just can't seem to find it. Can somebody help pls?

Alex
  • 11
  • 2
  • 2
    When you say "stay connected", are you talking about a [minimum spanning tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)? If so, search for Prim and Kruskal. Those algorithms will produce the MST, thus will indicate which edges were not used to create the MST. – PaulMcKenzie Jan 04 '22 at 13:22
  • 2
    Even if you want to implement this in C++, this is more of an algorithm question than a C++ question. So you might find help more quickly if you replace the tag – eike Jan 04 '22 at 13:23
  • 1
    These are called articulation points. You can find them in linear time – Artyer Jan 04 '22 at 13:32
  • Yes, the MST approach will do more work than finding the articulation points. @OP if you look at any of those algorithms, you will see that there is very little chance you would have came up with the code just "on your own". Was this a homework assignment given to you? – PaulMcKenzie Jan 04 '22 at 13:49
  • @PaulMcKenzie Sort of a homework, we started this in class but only a few people finished it, although I doubt they solved it using MST, since we haven't learned about it yet. Also, I should have been more specific, we're not supposed to find the MST, just to point out which element can be removed (without removing other elemets) so that the graph remains connected, and if there are multiple elements like the one found, to print all of them. – Alex Jan 04 '22 at 19:51
  • @Alex, when solving the MST, the edges that were not used to make the MST are the edges that can be removed and still have a connected graph. If you go to the wikipedia link and look at the picture of the graph that shows the MST, all of those greyed-out edges would be the answer to your question, no? – PaulMcKenzie Jan 04 '22 at 20:13
  • @PaulMcKenzie Yes, but, again, my bad for not being clear, I'm supposed to remove the vertices, not the edges, that would let the graph stay connected upon removing one of them. So, in other words, if I remove which vertex does the graph remain connected? – Alex Jan 04 '22 at 20:47
  • OK, so you're probably looking for Tarjan's algorithm to find the articulation points. – PaulMcKenzie Jan 05 '22 at 01:45
  • @PaulMcKenzie That's probably it. Thank you for helping and for your patience :) – Alex Jan 05 '22 at 18:22

0 Answers0