# Giant components of graph

**URL:** https://discourse.julialang.org/t/giant-components-of-graph/71361
**Category:** Graphs
**Tags:** question, graphs
**Created:** [November 12, 2021, 2:45am UTC](https://discourse.julialang.org/t/giant-components-of-graph/71361 "2021-11-12T02:45:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)
#### Post date: [November 12, 2021, 2:45am UTC](https://discourse.julialang.org/t/giant-components-of-graph/71361/1 "2021-11-12T02:45:34Z")

</div>

Dear all, Is there any function to get a subset of graph that have largest connected component using Graphs.jl (version \>= 1.4.1)? I only found function connected\_components that return a list of connected vertices?

In function connected\_components

```julia
g = SimpleGraph([0 1 0 0 0; 1 0 1 0 0; 0 1 0 0 0; 0 0 0 0 1; 0 0 0 1 0]);

connected_components(g)
2-element Array{Array{Int64,1},1}:
 [1, 2, 3]
 [4, 5]

```

What I need is a get\_largest\_component\_graph

```julia
g = SimpleGraph([0 1 0 0 0; 1 0 1 0 0; 0 1 0 0 0; 0 0 0 0 1; 0 0 0 1 0]);

giant_component_graph = get_largest_component_graph(g)

```

Is there any idea to create this get\_largest\_component\_graph? Thank you very much

---

<div class="post-metadata">

### Author: ![Jakob](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@Jakob](https://discourse.julialang.org/u/Jakob)
#### Post date: [November 12, 2021, 7:37am UTC](https://discourse.julialang.org/t/giant-components-of-graph/71361/2 "2021-11-12T07:37:10Z")

</div>

How about this?

```julia
function main_component(g)
    c = connected_components(g)
    _, i = findmax(length.(c))
    g[c[i]]
end

julia> g = erdos_renyi(1000, 1000)
{1000, 1000} undirected simple Int64 graph

julia> main_component(g)
{802, 970} undirected simple Int64 graph

```

---

<div class="post-metadata">

### Author: ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)
#### Post date: [November 14, 2021, 12:08am UTC](https://discourse.julialang.org/t/giant-components-of-graph/71361/3 "2021-11-14T00:08:15Z")

</div>

Great! Thank you so much for the solution.
