Binary Search Tree
Binary Search Tree??
バイナリナビゲーションツリー(バイナリナビゲーションに似ていますか?)あるいは李珍特里と呼ばれます.このツリーは、最大2つのサブノードで構成されます.そこで、左と右に分けます.すべての左側の子供はルートまたは親より小さい値であり、すべての右側の子供はルートまたは親より大きい特徴を持つバイナリツリーとして定義されます.
データの挿入、削除方法によって、バイナリツリーは完全バイナリツリー、完全バイナリツリー、飽和バイナリツリーに分けられます.
24162」完全バイナリツリー
?」」」」」」」」
class Node {
constructor(data, left = null, right = null){
this.data = data;
this.left = left;
this.right = right;
}
}
class BST {
constructor(){
this.root = null;
}
add(data){
const node = this.root;
if(node === null){
this.root = new Node(data);
return;
} else {
const searchTree = function(node){
if(data < node.data){
if(node.left === null){
node.left = new Node(data);
return;
} else if(node.left !== null){
return searchTree(node.left);
}
} else if(data > node.data){
if(node.right === null){
node.right = new Node(data);
return;
} else if(node.right !== null){
return searchTree(node.right);
}
} else {
return null;
}
};
return searchTree(node);
}
Reference
この問題について(Binary Search Tree), 我々は、より多くの情報をここで見つけました https://velog.io/@kbs5665/Binary-Search-Treeテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol