473,658 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Recursion and Circular References

I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. Any sugesstions on how to do this using c#.

Example,

ID DependsOnID
1 2
1 4
2 3
3 1 (circular reference)
Jul 10 '08 #1
5 3393
On Jul 10, 4:07*pm, Bob <B...@discussio ns.microsoft.co mwrote:
I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. *Any sugesstions on how to do this using c#..

Example,

ID * * *DependsOnID
1 * * * 2
1 * * * 4
2 * * * 3
3 * * * 1 *(circular reference)
What is the nature of the "table"? Is it an array of objects of some
sort, or a table in an SQL database?

Jul 10 '08 #2
I will probably pull the values from the SQL table into an array because it
will be faster to process programmaticall y.

"Pavel Minaev" wrote:
On Jul 10, 4:07 pm, Bob <B...@discussio ns.microsoft.co mwrote:
I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. Any sugesstions on how to do this using c#..

Example,

ID DependsOnID
1 2
1 4
2 3
3 1 (circular reference)

What is the nature of the "table"? Is it an array of objects of some
sort, or a table in an SQL database?

Jul 10 '08 #3
1. Push the first element to a stack.
2. Pull the first element, X, from the stack. If stack is empty, DONE.
If X is "marked", you have a circular reference: QUIT. Else "mark" the
element X.
3. Push all the elements that have a link in X on the stack.
4. Go to 2.

To "mark" an element either set an attribute in the object, or if this is
not possible, just keep the marked elements (or their id's) in a list and
check the list
to determine if an element has been "marked".

"Bob" <Bo*@discussion s.microsoft.com wrote in message
news:B3******** *************** ***********@mic rosoft.com...
>I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. Any sugesstions on how to do this using c#.

Example,

ID DependsOnID
1 2
1 4
2 3
3 1 (circular reference)

Jul 10 '08 #4
Starting with the set of nodes {S}, with attributes (From, To), find all
S.from NOT IN S.to. These nodes, {u} correspond to nodes having no parent.
Remove {u} from {S} to make the new {S} set. Repeat until {S} is empty. If
{u} happens to be empty while {S} is not, you have at least one cycle.
Now, do you really remove objects from a list, or do you just tag them (like
I would do for a database based algorithm) is up to you.

You can also start from all nodes S.to NOT IN S.from and obtain a LATEST
sequence instead of an EARLIEST sequence (if nodes are jobs, the first
sequence pops the jobs as soon as they are possible, while the second
sequence pop the jobs as late as possible).
Vanderghast, Access MVP

"Bob" <Bo*@discussion s.microsoft.com wrote in message
news:B3******** *************** ***********@mic rosoft.com...
>I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. Any sugesstions on how to do this using c#.

Example,

ID DependsOnID
1 2
1 4
2 3
3 1 (circular reference)
Jul 10 '08 #5
oracle has 'connect by'
http://www.databasejournal.com/featu...le.php/3552521

for ms sql
http://blogs.conchango.com/christian...11/09/234.aspx

also in old tran-sql books there was store proc simulating connct by
--
kk
"Bob" wrote:
I have a table of dependencies and want to check to see if the dependencies
cause a circular reference. Any sugesstions on how to do this using c#.

Example,

ID DependsOnID
1 2
1 4
2 3
3 1 (circular reference)
Jul 11 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2828
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more semi-circular definitions and
2
7974
by: Earth Worm Jim | last post by:
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular references when the circular reference is contained with in a collection class, specifically I am using a custom ArrayList object. I keep getting a StackOverFlow Exception from the XmlSerializer class when attempting the serialisation. The classes...
12
7052
by: Frank Rizzo | last post by:
I have a circular reference between 2 classes in the same project (i.e. each class refers to the other). The app runs fine and I am seeing no issues, which kind of surprised me. Are there any issues that I am not seeing (performance wise or garbage collection wise) with circular references? Thanks.
4
1216
by: Tiraman | last post by:
Hi , Problem description : I have 2 assemblies (A.dll And B.dll) . They are both under the GAC and they are both using the functions of each other . Each time that I m doing a change in one of them I need to change the
3
4395
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
20
2986
by: athar.mirchi | last post by:
..plz define it.
3
2915
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far better than the amount of errors I was originally getting on builds before I consilidated by UC's though :-) "Paul Hale" wrote:
0
2817
balabaster
by: balabaster | last post by:
Hi, I have a couple of tables: Units( Unit_PKey Int Identity(1,1) Primary Key, Unit_Name nvarchar(8), Unit_Description nvarchar(32) )
3
2940
by: shapper | last post by:
Hello, On an ASP.NET MVC project I am getting a list of Tags which names start with a string contained on the variable "q". Everything works fine if no Post is related to Tags. When there is relation I start to get a Circular Reference error. I have been trying to solve this problem for days! I can't find the reason for this, either in my SQL or C# code.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.