Group Abstract Group Abstract

Message Boards Message Boards

2
|
5.1K Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Given a graph and a subset of its nodes, how to get the induced subgraph?

Posted 7 years ago
POSTED BY: Szabolcs Horvát
2 Replies
POSTED BY: Szabolcs Horvát

I believe I found a robust way to do it:

Subgraph[g, Verbatim /@ vs]

The problem is that it kills performance.

rg = RandomGraph[{10000, 30000}];
vs = RandomSample[VertexList[rg], 100];

Subgraph[rg, vs]; // RepeatedTiming
(* {0.00024, Null} *)

Subgraph[rg, Verbatim /@ vs]; // RepeatedTiming
(* {5.14, Null} *)

Thus is it not really a practically usable solution.

I think that a workable fix would be to always interpret a List-second argument as a list in Subgraph (and never as a single vertex or single pattern). Thus the single-vertex syntax, Subgraph[g, v] would still be problematic, but at least the Subgraph[g, {v1, v2, ...}] syntax would always be unambiguous.

This, however, would become a usability problem with VertexDelete where people will use the single-vertex syntax much more frequently.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard