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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:24:43+00:00 2026-05-16T06:24:43+00:00

There are many articles in this site regarding my question. I have a matrix

  • 0

There are many articles in this site regarding my question.
I have a matrix for example (10 x 10) which represents 10 nodes. The matrix called MyMat(9,9)

The rows of this matrix represent the source node (From Node) and the columns represents target node (To Node). It has 14 links which are randomly distributed. The non zero values represent the connections between nodes.

0 0 0 0 1 0 0 0 0 0 
0 0 0 1 0 0 0 0 1 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0 0
0 1 1 0 0 1 0 0 0 0

What I want is to prevent the loops (cycles) for each node in the system. For example:
Node 1: No loop

Node 2: 2, 9, 7, 8, 10, 2. Here the loop exists because it started with 2 and finished with 2. What I want to prevent the loops in this network. This means that: MyMat(9,1) must be 0
Node 2: 2, 9, 7, 8, 10, 3, 2. This means MyMat(2,1) must be 0

Node 3: No loop

Node 4: 4, 7, 8, 4. This means that MyMat(7,3) must be 0

Node 5: 5, 8, 10, 6, 5. This means that MyMat(5,4) must be 0

Node 6: No Loop

Node 7: No Loop

Node 8: No Loop

Node 9: No Loop

Node 10: No Loop

4 connections were deleted from above matrix.

I have done this via a technique called Depth first search but it is very slow and burden the running time of my programme especially when I use 60 nodes and 100 connections!!
Several programming examples can found if you Google it.

Is there an easier (quicker) way for doing this in visual basic or C#?

  • 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-05-16T06:24:44+00:00Added an answer on May 16, 2026 at 6:24 am

    Depth first search should not take very long at all.

    Procedure Depth_First_Clean(graph, v){
      color v grey
      for each edge (v,u){
         if u is grey 
           delete edge (v,u)
         else if u is white
           Depth_First_Clean(graph, u)
      }
      color v black
    }
    
    Procedure Clean_all(graph) {
      Mark all nodes white
      While there are white nodes left {
        v = a white node
        Depth_First_Clean(graph, v)
      }
    

    This traverses each edge once, so should take almost no time in a graph with 100 edges.

    OK from the example (I’m going to renumber the nodes to get rid of the confusing off by one problem in your example we have

      0 1 2 3 4 5 6 7 8 9
    0 0 0 0 0 1 0 0 0 0 0 
    1 0 0 0 1 0 0 0 0 1 0
    2 0 1 0 0 0 0 0 0 0 0
    3 0 0 0 0 0 0 1 0 0 0
    4 0 0 0 0 0 0 0 1 0 0
    5 0 0 0 0 1 0 0 0 0 0
    6 0 0 0 0 0 0 0 1 0 0
    7 0 0 0 1 0 0 0 0 0 1
    8 0 0 0 0 0 0 1 0 0 0
    9 0 1 1 0 0 1 0 0 0 0
    
    we mark all nodes white.  
    We start with node 0
      mark node 0 grey
       traverse edge (0,4)
         mark node 4 grey
           traverse edge (4, 7)
             mark node 7 grey
               traverse edge (7, 3)
                 mark node 3 grey 
                   traverse edge (3,6)
                     mark node 6 grey
                       delete edge (6, 7) -- node 7 is grey break cycle 7 3 6 7
                     color node 6 black
                 color node 3 black 
               traverse edge (7, 9)
                 mark node 9 grey
                   traverse edge (9, 1)
                     mark node 1 grey
                       skip edge (1,3) -- 3 is black there are no cycles through 3
                       traverse edge (1, 8)
                         mark node 8 grey
                           skip edge (8, 6)
                         color node 8 black
                     color node 1 black
                   traverse edge (9, 2)   
                     color node 2 grey
                       skip edge (2,1)
                     color node 2 black
                   traverse edge (9, 5)
                     color node 5 grey
                       delete edge (5, 4)
                     color node 5 black
                 color node 9 black
             color node 7 black       
         color node 4 black       
     color node 0 black       
    None of the remening nodes are white so we are done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem with ScrollView zoom. There are many articles about it but
I've read many different articles/threads on this, but have yet to determine the best
I have read through other questions on this site - using the example answer
I read several articles on this site and many others recommending report generating tools
There are many ways of converting a String to an Integer object. Which is
Okay so I have this web site search script and I'm trying to count
Many articles (e.g. msdn ) have said that a circular reference cannot be cleaned
Im running a Joomla 1.5 site where there are many pages being indexed by
This question is bit specific for Joomla. I have a main menu consisting of:
I have been searching for an answer to this question for days and it

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.