Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:15:33+00:00 2026-06-01T15:15:33+00:00

Given a node x in an undirected graph that is known to be part

  • 0

Given a node x in an undirected graph that is known to be part of a connected component, I seek to find all nodes belonging to the component of x.

My current implementation identifies all components in the undirected graph and is therefore inneficient for large graphs. I currently use connectedComp from ggm library to do this, but would rather run a BFS from RBGL starting at node x and terminating once its component is fully explored. Any suggestions on how to do this? Also, any information on parallel graph algorithm implementations that can be called from R would be appreciated.

library("ggm")
x <- 2

> graph
   1 2 3 4 5 6 7 8 9 10
1  0 0 0 0 0 0 0 0 0  0
2  0 0 1 0 0 1 0 0 0  0
3  0 1 0 0 0 1 1 1 0  0
4  0 0 0 0 0 0 0 0 0  0
5  0 0 0 0 0 0 0 0 0  0
6  0 1 1 0 0 0 0 0 0  0
7  0 0 1 0 0 0 0 0 0  0
8  0 0 1 0 0 0 0 0 0  0
9  0 0 0 0 0 0 0 0 0  0
10 0 0 0 0 0 0 0 0 0  0

graph_object <- as(graph, "graphNEL")

# All connected components of graph using connectedComp function:
comp_list <- connectedComp(graph_object)
> comp_list
$`1`
[1] "1"

$`2`
[1] "2" "3" "6" "7" "8"

$`3`
[1] "4"

$`4`
[1] "5"

$`5`
[1] "9"

$`6`
[1] "10"

# Extract adjacency matrix of component containing x:

comp_x <- seq_along(comp_list)[sapply(comp_list, FUN=function(list) x %in% list)]
> comp_x
[1] 2

comp_x_list <- comp_list[[comp_x]]
> comp_x_list
[1] "2" "3" "6" "7" "8"

comp_x <- graph[comp_x_list, comp_x_list]
> comp_x
  2 3 6 7 8
2 0 1 1 0 0
3 1 0 1 1 1
6 1 1 0 0 0
7 0 1 0 0 0
8 0 1 0 0 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:15:35+00:00Added an answer on June 1, 2026 at 3:15 pm

    In my opinion preprocessing graph with Union-find will give you best results.
    It would be faster if you store graph as list of edges instead of adjacency matrix.

    If you need parallel solution, then you should read about bfs in hadoop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the Lemon C++ Graph Library, given a node in an undirected graph say,
Given a directed graph, the goal is to combine the node with the nodes
Given an undirected graph in which each node has a Cartesian coordinate in space
I need to find all block elements in a given node. Block elements are
Given an undirected graph with n nodes, where each of the nodes has a
I want all the childs of given node in YUI treeview. Condition is that
Given an undirected graph, I want to generate all subgraphs which are trees of
I have undirected graph with 57 nodes and 204 linkages. I calculate the shortest
For a given node I need to find the total number of sub tree
I'm trying to write a subroutine in Perl that will delete a given node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.