# Basic cycles in a un-directed gaph

**URL:** <https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835>\
**Category:** Specific Domains\
**Tags:** question\
**Created:** [March 23, 2017, 1:24pm UTC](https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835 "2017-03-23T13:24:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TsurHerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tsurherman/32/1234_2.png) [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)\
**Post date:** [March 23, 2017, 1:24pm UTC](https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835/1 "2017-03-23T13:24:00Z")

</div>

I have a situation that can be reduced to finding basic cycles in an undirected graph of length 4(the cycles require to be length 4)

I don’t have much previous experience with graphs, but this seems a simple operation  
for someone proficient in this field.

Is there an existing julia package with this functionality?

---

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [March 23, 2017, 2:29pm UTC](https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835/2 "2017-03-23T14:29:53Z")

</div>

Not an expert, but it’s probably with [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl) 👍

---

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [March 23, 2017, 2:41pm UTC](https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835/3 "2017-03-23T14:41:42Z")

</div>

We have basic cyclicity tests in LightGraphs. If you get stuck or can’t find what you need in the docs, feel free to open up an issue there and we can try to help further.

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [March 23, 2017, 4:44pm UTC](https://discourse.julialang.org/t/basic-cycles-in-a-un-directed-gaph/2835/4 "2017-03-23T16:44:47Z")

</div>

If you are looking for a _basis of fundamental cycles_, then you should start with a spanning tree (as a subgraph). All other edges (u,v) define a cycle by joining them with the unique path from u to v in the spanning tree.

If you just want to find any cycle or show that none exist, you could look at [this function](https://github.com/leethargo/PipeLayout.jl/blob/master/src/topology/util.jl#L48) that I use myself. It is based on a user type, but immediatly converts it to a LightGraphs type, so you should be fine.
