# Use Depth First Search in a Binary Search Tree

**URL:** <https://forum.freecodecamp.org/t/use-depth-first-search-in-a-binary-search-tree/436065>\
**Category:** freeCodeCamp Contributors\
**Tags:** contributing\
**Created:** [December 18, 2020, 3:04am UTC](https://forum.freecodecamp.org/t/use-depth-first-search-in-a-binary-search-tree/436065 "2020-12-18T03:04:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavinmacken87](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gavinmacken87/32/193633_2.png) [@gavinmacken87](https://forum.freecodecamp.org/u/gavinmacken87)\
**Post date:** [December 18, 2020, 3:04am UTC](https://forum.freecodecamp.org/t/use-depth-first-search-in-a-binary-search-tree/436065/1 "2020-12-18T03:04:27Z")

</div>

**What is your hint or solution suggestion?**

> ****
>
> ```auto
> var displayTree = tree => console.log(JSON.stringify(tree, null, 2));
> function Node(value) {
> this.value = value;
> this.left = null;
> this.right = null;
> }
> function BinarySearchTree() {
> this.root = null;
> // Only change code below this line
> var inorder = [];
> var preorder = [];
> var postorder = [];
> this.inorder = function(root = this.root){
> if(!root){
> return null
> }
> 
> this.inorder(root.left);
> inorder.push(root.value)
> this.inorder(root.right);
> return inorder
> }
> 
> this.preorder = function(root = this.root){
> if(!root){
> return null
> }
> 
> preorder.push(root.value)
> this.preorder(root.left);
> this.preorder(root.right);
> return preorder
> }
> 
> this.postorder = function(root = this.root){
> if(!root){
> return null
> }
>     
> this.postorder(root.left);
> this.postorder(root.right);
> postorder.push(root.value);
> 
> return postorder
> }
> // Only change code above this line
> }
> 
> ```

**Challenge:** Use Depth First Search in a Binary Search Tree

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/use-depth-first-search-in-a-binary-search-tree)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [December 18, 2020, 4:21am UTC](https://forum.freecodecamp.org/t/use-depth-first-search-in-a-binary-search-tree/436065/2 "2020-12-18T04:21:23Z")

</div>

HI @gavinmacken87!

Welcome to the forum!

Thank you, for your contribution. For future contributions, please wrap your solution within :

````nohighlight
[details]
```
code goes here...
```
[/details]

````

Also, provide **all** of the necessary code to pass the challenge.

Also, when you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor ( `</>` ) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](http://www.freecodecamp.com/forum/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:32pm UTC](https://forum.freecodecamp.org/t/use-depth-first-search-in-a-binary-search-tree/436065/3 "2021-06-01T18:32:01Z")

</div>

Closed on June 1, 2021, 6:32pm UTC


