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 7968165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:02:03+00:00 2026-06-04T07:02:03+00:00

I have a boolean[][] 2D-array called matrix , which encodes a directed graph such

  • 0

I have a boolean[][] 2D-array called matrix, which encodes a directed graph such that if matrix[i][j] == true, then vertex j is connected to vertex i (the inverse is not necessarily true).
I’m trying to create a Java method that will determine how many disjoint directed graphs I have.

So for Example, if vertex 0 was connected to vertex 1, and vertex 2 was connected to vertex 3
(<code>[{{0,0,0,0},{1,0,0,0},{0,0,0,0},{0,0,1,0}}]</code> would be the 2D array), I would have 2 disjoint digraphs.

If there are no connections, the number of disjoint digraphs would equal the number of vertices.

  • 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-04T07:02:04+00:00Added an answer on June 4, 2026 at 7:02 am

    Start with a list of all of the nodes in the tree. Consider these your unvisited nodes.

    Then repeat the following process until your list of unvisited nodes is gone.

    1. Create an empty set, the “node-set”, to represent the nodes that live in the current node’s graph.
    2. Perform a search starting at the current node. For each node you encounter in the search, remove it from your unvisited node list, then: (1) if the node already exists in another node-set, merge the current node-set and that other node-set and stop your search from that node, or (2) if that node already exists in the current node-set, stop your search from that node, or (3) if you have never seen that node, add it to the current node-set.

    Once this process is complete, your node-sets correspond to the nodes that uniquely exist in each disjoint graph, so the number of node-sets is the value you seek.

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

Sidebar

Related Questions

Say I have a 2D array of random boolean ones and zeroes called 'lattice',
I have an array of objects, where one field is a boolean field called
I have a boolean setting in my Properties/Settings.settings file, which basically stores per user
I am creating an android application using Java. I have a boolean variable called
I have an array of points (called points ), consisting of ~30000 x,y, and
I have an array of values called A, B... X, Y, Z. Fun though
In short, I have an object called PersonList that has a List of Person
I have a boolean array call it flag . I have two numeric arrays
In my model I have one int object and a boolean array: public class
So I have an in_array check, called if (in_array('pageLevel',$userlevels)) Which I want to connect

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.