## Given a Spanning Tree and an Edge Not on the Spanning Tree, How to Form a Cycle Base?

### Remember to vote up questions/answers you find interesting or helpful (requires 15 reputation points)

I have a graph with Edge `E` and Vertex `V`, I can find the spanning tree using Kruskal algorithm, now I want to find all the cycle bases that are created by utilitizing that spanning tree and the edges that are not on the tree, any algorithm that allows me to do that, besides brute force search?

I can, of course, starts from one vertex of the non-spanning tree edge, gets all the edges, explore all of them, retracts if I find dead end, until I come back to the other vertex of the edge. But this is a bit, err... brutal. Any other ideas?

-

You don't need Kruskal, Ngu! You can find a spanning tree trivially -- it doesn't have to be minimum. Newcomers, see mathoverflow.net/questions/1443/… for Ngu's initial question. – TonyK Oct 22 2009 at 18:15
Sure, I can find spanning tree-- with or without Kruskal. But my question is how to form the cycle base without resorting to something what I call 'brute force'. – Graviton Oct 23 2009 at 1:34

## 2 Answers

I think you're likely to get better answers if you post this question on Stack Overflow rather than here.

But anyways, if your graph doesn't have weights on edges, you don't need Kruskal's algorithm to find a spanning tree; you can just use DFS. As you compute the tree, store for each vertex its parent and the distance to the root. Then when you encounter a non-tree edge, you can find the nearest common ancestor of its two endpoints efficiently.

-

Even with weights, you can use DFS to find a spanning tree.  It might not have any nice properties, though. – Michael Lugo Oct 22 2009 at 18:03
>if your graph doesn't have weights on edges  I agree, but But my question is how to form the cycle base without resorting to something what I call 'brute force'.   – Graviton Oct 23 2009 at 1:34

### You can accept an answer to one of your own questions by clicking the check mark next to it. This awards 15 reputation points to the person who answered and 2 reputation points to you.

Although this thread is long-dead, there is a very simple way to do this with linear algebra, so I will post an answer.

You are interested in a basis of the cycle space of $G$. Orient $G$ in any way. Let $\partial(G)$ be the edge-vertex incidence matrix of $G$. A basis of the cycle space is given by a basis for $\ker \partial(G)$. To get the answer to your question note that if you take any spanning tree $T$ and you consider the edges of $E-T$, there will be a unique element of the cycle space that is $1$ on a given edge of $E-T$ and $0$ on the others. Finding such an element for each edge of $E-T$ will yield a new basis for $\ker \partial(G)$.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 12, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9236314296722412, "perplexity_flag": "head"}