BinarySearchTree

BinarySearchTree

Binary Search Tree에 저장되어 있는 요소들은 트리 형태로 표현되며 요소 간에 부모, 자식 관계가 크기 비교에 의해서 존재한다. 자식이 부모보다 클 경우 부모의 오른쪽 노드로, 자식이 부모보다 작을 경우 부모의 왼쪽 노드로 저장된다

Constructor

new BinarySearchTree()

Author:
  • seeung0305@naver.com
Example
var bst = new BinarySearchTree ();

Methods

(static) clear(value)

This method is used to nullify this binary search tree and make all variables initial.
Example
var bst = new BinarySearchTree ();
bst.push(1);
bst.push(2);
bst.push(3);
bst.clear(this.root);
Parameters:
Name Type Description
value undefined The value which Recursively removes the children of the value from the tree.
Throws:
This method returns false if the parameter is missing or null the node of which data is value is not among binary search tree.

(static) delete(value)

This method removes the node from the tree of which data is same as value
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.find(2); // return node
bst.delete(2); // 2 will be removed
bst.find(2); // return null
Parameters:
Name Type Description
value undefined The value of node which is in the binary search tree.
Throws:
This method returns false if the parameter is missing or null the node of which data is value is not among binary search tree.

(static) find(value) → {Node}

This method finds the node from the tree of which data is same as value.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.find(3); // return null
bst.insert(3);
bst.find(3); // return node
Parameters:
Name Type Description
value undefined The value to look up the node which has data as same as value among the binary search tree.
Throws:
This method returns 'false' if the parameter is missing or null if the node of which data is same as value doesn’t exist.
Returns:
This method returns node which has data as same as value.
Type
Node

(static) inOrder(value)

This method is used for tree traversal. Traversal order is left -> parent -> right.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.insert(3);
bst.inOrder(this.root);
Parameters:
Name Type Description
value undefined The value is used to tree traversal recursively.
Throws:
This method returns false if the parameter is missing or null if node has no data.

(static) insert(value)

This method is used to insert the specified value into this binary search tree.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
Parameters:
Name Type Description
value undefined The value to be inserted to this binary search tree.
Throws:
This method returns null if the parameter is missing.

(static) isEmpty() → {Boolean}

This method is used to check if this binary search tree is empty.
Example
var bst = new BinarySearchTree ();
var ret1 = bst.isEmpty();  // ret1 = true
bst.insert(1);
var ret2 = bst.isEmpty();  // ret2 = false
Returns:
This method returns 'true' if this birnary search tree is empty or 'false' if this birnary search tree isn't empty.
Type
Boolean

(static) maxValue(value) → {Node}

This method finds the node which has the maximum data among the value’s child.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.maxValue(this.root);
Parameters:
Name Type Description
value undefined The value which intends to look for the maximum data of nodes among children.
Throws:
This method returns false if the parameter is missing or null if node has no data.
Returns:
This method returns node or the minimum data from the child nodes of value recursively.
Type
Node

(static) minValue(value) → {Node}

This method finds the node which has the minimum data among the value’s child.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.minValue(this.root);
Parameters:
Name Type Description
value undefined – The value which intends to look for the minimum data of nodes among children.
Throws:
This method returns false if the parameter is missing or null if node has no data.
Returns:
This method returns node or the minimum data from the child nodes of value recursively.
Type
Node

(static) state()

This method shows state of the binary_search_tree.
Example
var bst = new BinarySearchTree ();
bst.insert(1);
bst.insert(2);
bst.insert(3);
bst.state();