File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ Trigger production build
2727
2828# List of Data Structures
2929Data structures covered so far -
30- - [ Binary Search Tree] ( https://github.com/linux-nerd/data-structures.js/wiki/Binary-Search-Tree )
30+ - [ Binary Search Tree] ( #binary-search-tree )
3131
3232# Contribution
3333Your contribution is highly appreciated. You can contribute in several ways -
@@ -51,3 +51,41 @@ and will be published in
5151- bower
5252
5353
54+ # <a name =" binary-search-tree " ></a >Binary Search Tree
55+ Import BST class and instantiate it
56+ ``` js
57+ import { BST } from ' data-structures.js/lib/data-structures' ;
58+ const bst = new BST
59+ ```
60+
61+ Insert values in binary search Tree
62+ ``` js
63+ bst .insert (5 );
64+ bst .insert (20 );
65+ bst .insert (10 );
66+ ```
67+ Find size of the binary search tree
68+ ``` js
69+ bst .len () // 3
70+ ```
71+
72+ Find an item in the binary search tree
73+ ``` js
74+ bst .lookup (10 ) // returns an object with keys hasVal, currentNode and parentNode
75+ ```
76+
77+ Height of the binary search tree or a node
78+ ``` js
79+ bst .height () // gives height of the BST 1
80+ bst .height (bst .lookup (10 ).currentNode ) // gives the height of the node - 0
81+ ```
82+
83+ Traverse the BST and return a List
84+ ``` js
85+ bst .traverse (' inOrder' ) // traverse method expects a parameter - inOrder|preOrder|postOrder| levelOrder
86+ ```
87+ Delete elements from binary search tree
88+ ``` js
89+ bst .delete (10 );
90+ bst .delete (20 );
91+ ```
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ export class BST {
213213 retVal = this [ levelOrderTraversal ] ( ) ;
214214 break ;
215215 default :
216- retVal = new Error ( 'Type should be one of inOrder, preOrder or postOrder ' ) ;
216+ retVal = new Error ( 'Type should be one of inOrder, preOrder, postOrder or levelOrder ' ) ;
217217 break ;
218218 }
219219
@@ -298,4 +298,4 @@ export class BST {
298298
299299 return bfsTraversalList ;
300300 }
301- }
301+ }
You can’t perform that action at this time.
0 commit comments