---
title: "Cycle Component"
description: "Overview of TigerGraph's implementation of the Cycle Component algorithm"
component: "graph-ml"
version: "3.10"
module: "pathfinding-algorithms"
html_url: "/graph-ml/3.10/pathfinding-algorithms/cycle-component"
canonical_url: "https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/cycle-component"
markdown_url: "https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/cycle-component.md"
---

[View as HTML](https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/cycle-component)

# Cycle Component

Algorithm link: [Cycle Component](https://github.com/tigergraph/gsql-graph-algorithms/blob/master/algorithms/Path/cycle%5Fcomponent/tg%5Fcycle%5Fcomponent.gsql)

The Cycle Component algorithm finds vertices that are on a cycle. It can be used as a helper algorithm for the [Cycle Detection](https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/cycle-detection.md) algorithm. It returns a set of only the vertices which are on at least one cycle, which saves memory compared to finding and returning all cycles.

## Specifications

```gsql
CREATE QUERY tg_cycle_component(STRING v_type, STRING e_type, BOOL print_results = TRUE, STRING result_attribute =  "", STRING file_path = "")
```

### Parameters

| Parameter | Data type | Description |
| --- | --- | --- |
| `v_type` | `STRING` | The type of vertex to search for. |
| `e_type` | `STRING` | The type of edge to search for. |
| `print_results` | `BOOL` | Whether or not to print the path to the console. |
| `result_attribute` | `STRING` | The attribute on the vertex that will store the result. |
| `file_path` | `STRING` | If not empty, write output to this file. |

### Output

This query returns the vertices that appear on at least one cycle in JSON format.

### Time complexity

This algorithm has a time complexity of \\(O(VE)\\), where \\(V\\) is the number of vertices and \\(E\\) is the number of edges.

### Space complexity

This algorithm has a space complexity of \\(O(V)\\), where \\(V\\) is the number of vertices.

## Example

You can run this query on the default Friendship graph included with the Getting Started with Docker tutorial.

![cycle component graph dark](https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/_images/cycle-component-graph-dark.png) 

In this graph, there is a cycle that includes Tom, Dan, and Jenny. Running tg\_cycle\_component returns those three vertices.

![cycle component results dark](https://www.tigergraph.com/docs/graph-ml/3.10/pathfinding-algorithms/_images/cycle-component-results-dark.png) 

```none
[
  {
    "V": [
      {
        "attributes": {
          "@or_nocycle": false,
          "@sum_outdegree": 2,
          "@sum_outdegree_curr": 0,
          "age": 40,
          "gender": "male",
          "name": "Tom",
          "state": "ca"
        },
        "v_id": "Tom",
        "v_type": "Person"
      },
      {
        "attributes": {
          "@or_nocycle": false,
          "@sum_outdegree": 4,
          "@sum_outdegree_curr": 2,
          "age": 34,
          "gender": "male",
          "name": "Dan",
          "state": "ny"
        },
        "v_id": "Dan",
        "v_type": "Person"
      },
      {
        "attributes": {
          "@or_nocycle": false,
          "@sum_outdegree": 3,
          "@sum_outdegree_curr": 1,
          "age": 25,
          "gender": "female",
          "name": "Jenny",
          "state": "tx"
        },
        "v_id": "Jenny",
        "v_type": "Person"
      }
    ]
  },
  {
    "\"tg_cycle_component works!\"": "tg_cycle_component works!"
  }
]
```
