-1

Trivial graph question. For a small DAG, meaning a few hundred vertices and probably never more than 1,000, given a few of the vertices v ⊂ V I want to remove all edges & vertices except those connecting v (edit: so the output may contain other vertices not in v).

This is not graph contraction as it doesn't merge vertices, it's more like graph "pruning" I suppose.

Graph representation is anything you like so long as it's reasonably compact so adjacency matrix is prob. out.

I can do this myself with refcounting and recursively deleting any nodes with no in/out (should work?), but I'd rather just pull an off the shelf algo and be done with it, if it's simpler.

If the graph is partitioned so there are no edges connecting v (it's a forest, technically?), report an error. If the graph is not a DAG so is cyclic, it'd be helpful if it detected and reported this, though not essential. The edges are unweighted. This isn't a minimum spanning tree as v ⊂ V not all of V.

Background: consider an SQL schema with tables (V) and foreign keys (E) joining them. Given a few tables, I want the subgraph of those + FK joining them + any tables they go through.

If there is a name for this problem, what is it? (that would also help me find existing libraries to do this).

thanks

user3779002
  • 419
  • 3
  • 12

0 Answers0