# Most efficient way to find ancestors of a node

**URL:** <https://igraph.discourse.group/t/most-efficient-way-to-find-ancestors-of-a-node/666>\
**Category:** Usage\
**Tags:** Python\
**Created:** [11 March 2021 16:23 UTC](https://igraph.discourse.group/t/most-efficient-way-to-find-ancestors-of-a-node/666 "2021-03-11T16:23:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://igraph.discourse.group/u/Dave)\
**Post date:** [11 March 2021 16:23 UTC](https://igraph.discourse.group/t/most-efficient-way-to-find-ancestors-of-a-node/666/1 "2021-03-11T16:23:49Z")

</div>

What is the most efficient way to find the ancestors (parents) of a particular node?

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [11 March 2021 19:33 UTC](https://igraph.discourse.group/t/most-efficient-way-to-find-ancestors-of-a-node/666/2 "2021-03-11T19:33:41Z")

</div>

You can find the “in” and “out” components of a node using the [`subcomponent`](https://igraph.org/python/doc/api/igraph._igraph.GraphBase.html#subcomponent) function, e.g. `G.subcomponent(v, mode=ig.IN)`. This functions returns all nodes that can reach the node `v` (when using `ig.IN`) or all nodes that can be reached by node `v` (when using `ig.OUT`).
