12,548,647 members (53,050 online)
Rate this:
See more:
I need to write a method to find the count of 4 cycles(cycles containing 4 edges) in an undirected graph. Please give me some advices if you have any idea about the algorithm.
Posted 1-Feb-13 2:43am
Andreas Gieriet 2-Feb-13 6:10am

Why do you add a solution to your own questions. Use [Improve question] button here above and [x] delete your solution below.
Andi

Rate this:

## Solution 1

See Robert Sedgewick[^]'s book list: Part 5: Graph Algorithms is the book to read (you choose: C, C++, Java). It would be a nice exercise if you write all the code of the book in C#. ;-)
Cheers
Andi
v4
venera_soft 2-Feb-13 2:06am

Thanks, will try :)
Rate this:

## Solution 2

I have done this myself. The algorithm uses DFS. And on every step it goes 4 levels and finds if the found vertex is the same as the one for which is done the step. In formal language it should be something like this:

```for path in dfs(start=node, max_depth=4):
if len(path) == 4 and path[1] == path[4]:
output.append(path)```

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Suvendu Shekhar Giri 115 Dave Kreskowiak 100 ppolymorphe 100 OriginalGriff 95 Rbabs 75
 OriginalGriff 3,892 Suvendu Shekhar Giri 1,713 John Simmons / outlaw programmer 1,687 ppolymorphe 1,541 Karthik Bangalore 1,210

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 2 Feb 2013