# Tree Traversal

**URL:** <https://community.neo4j.com/t/tree-traversal/9955>\
**Category:** General\
**Created:** [September 8, 2019, 6:05am UTC](https://community.neo4j.com/t/tree-traversal/9955 "2019-09-08T06:05:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mansour\_shams](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mansour_shams/32/3913_2.png) [@mansour\_shams](https://community.neo4j.com/u/mansour_shams)\
**Post date:** [September 8, 2019, 6:05am UTC](https://community.neo4j.com/t/tree-traversal/9955/1 "2019-09-08T06:05:55Z")

</div>

Hello,

What are the options in traversing a tree (say depth first) with Neo4j? Is bllom capable of doing this or is there any declarative approach to do so?

Thank you.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [September 8, 2019, 12:23pm UTC](https://community.neo4j.com/t/tree-traversal/9955/2 "2019-09-08T12:23:43Z")

</div>

If you want to write a java program that interacts with Neo4j, there is an entire traversal API for java that does exactly this, and traversing in any way you want, like depth first, is easy:

> **[Using Neo4j embedded in Java applications - Java Reference](https://neo4j.com/docs/java-reference/current/java-embedded/)**
>
> How to use Neo4j embedded in Java applications.

As for cypher -- you can definitely traverse a tree easily using it, but you can't do it depth first per se. Cypher is a declarative language, that means that you specify what you want, and _not_ how to get it. If you say you want depth first traversal, then that is fundamentally not declarative, but rather an imperative way of accessing the graph, and that's what the Java API is there for.

Ultimately both are supported, by Cypher's great strength is that you don't have to know or care which way the traversal goes. You just focus on specifying where you want to traverse to, and it gets you the data you want.

---

<div class="post-metadata">

**Author:** ![mansour\_shams](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mansour_shams/32/3913_2.png) [@mansour\_shams](https://community.neo4j.com/u/mansour_shams)\
**Post date:** [September 8, 2019, 1:16pm UTC](https://community.neo4j.com/t/tree-traversal/9955/3 "2019-09-08T13:16:03Z")

</div>

Hi David,

Thank you for your reply. I am using version 1.2.1 and was wondering what add-on etc. I need to install for the Java API and interfacing and providing the code. Is this compiled or is it interpreted? How is the interface? Also, are there any programs such as Bloom that can do this traversal?

It seems that the link you provided above assumes that person already knows the answers to the above questions.

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [September 9, 2019, 10:24pm UTC](https://community.neo4j.com/t/tree-traversal/9955/4 "2019-09-09T22:24:00Z")

</div>

You can also use the Expander procedures in the APOC procedure library:

[https://neo4j.com/docs/labs/apoc/current/graph-querying/](https://neo4j.com/docs/labs/apoc/current/graph-querying/)

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [September 9, 2019, 10:26pm UTC](https://community.neo4j.com/t/tree-traversal/9955/5 "2019-09-09T22:26:04Z")

</div>

The Java API that comes with Neo4j is what you use to access the traversal API. Here are the relevant docs for writing java programs. As such, they're compiled, not interpreted.

> **[Using Neo4j from Java - Developer Guides](https://neo4j.com/developer/java/)**
>
> If you are a Java developer, this guide provides an overview of options for connecting to Neo4j.

Bloom does not support this kind of traversal because it's focused on visualization. The interface of what I'm talking about is straight java code.

I recommend you try this out, go a bit further down the learning path, and then come back and post a follow-up question that's a bit more specific, on what kind of traversal you're trying to do, what you've tried, and so on.
