# How to get subgraphs and the largest component of a graph

**URL:** <https://igraph.discourse.group/t/how-to-get-subgraphs-and-the-largest-component-of-a-graph/1896>\
**Category:** Usage\
**Tags:** Python\
**Created:** [15 November 2024 14:03 UTC](https://igraph.discourse.group/t/how-to-get-subgraphs-and-the-largest-component-of-a-graph/1896 "2024-11-15T14:03:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![logion2000](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@logion2000](https://igraph.discourse.group/u/logion2000)\
**Post date:** [15 November 2024 14:03 UTC](https://igraph.discourse.group/t/how-to-get-subgraphs-and-the-largest-component-of-a-graph/1896/1 "2024-11-15T14:03:43Z")

</div>

I have two questions related to subgraphs.  
(1). What is the difference between graph.subgraph() and graph.induced\_subgraph()? Are they the same function?  
(2). How can I get the largest component (i.e., subgraph) of a graph? Assume the size of the graph means the number of vertices in the graph. Is there a function to do this? Or what code can achieve the goal?  
Thanks.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [15 November 2024 19:38 UTC](https://igraph.discourse.group/t/how-to-get-subgraphs-and-the-largest-component-of-a-graph/1896/2 "2024-11-15T19:38:52Z")

</div>

> [@logion2000](#):
>
> (1). What is the difference between graph.subgraph() and graph.induced\_subgraph()? Are they the same function?

Yes, they are the same.

@tamas, is `subgraph` deprecated?

> [@logion2000](#):
>
> (2). How can I get the largest component (i.e., subgraph) of a graph? Assume the size of the graph means the number of vertices in the graph. Is there a function to do this? Or what code can achieve the goal?

`g.connected_components().giant()`

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [18 November 2024 12:13 UTC](https://igraph.discourse.group/t/how-to-get-subgraphs-and-the-largest-component-of-a-graph/1896/3 "2024-11-18T12:13:18Z")

</div>

> [@szhorvat](#):
>
> @tamas, is `subgraph` deprecated?

Yes, it is, but it’s not marked formally as deprecated. It’s not worth the fuss as it is literally a one-line alias and it does not hurt anyone to keep it around.
