
Node๋ก ์ด๋ฃจ์ด์ง ์๋ฃ๊ตฌ์กฐ๋ก, ์คํ/ํ์ ๊ฐ์ ์ ํ ๊ตฌ์กฐ(Linear)๊ฐ ์๋ ๋น์ ํ(Non-linear) ๊ตฌ์กฐ
ํธ๋ฆฌ = Node์ Link์ ์งํฉ
(= ํ๋์ ์๋ฃ ๋ค์ ์ฌ๋ฌ ๊ฐ์ ์๋ฃ๊ฐ ์กด์ฌํ ์ ์๋ ํํ)
์๋ฃ๋ค๊ฐ์ ์, ๋ค ๊ด๊ณ๊ฐ 1: n ๋๋ n:n์ ๊ด๊ณ๋ฅผ ๋ํ๋ด๋ฉฐ, ๊ณ์ธต์ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ด๊ธฐ์ ์ ์

ํจ๋ ์์ผ๋ฉด ๋ญํ๋... ๊ท์ฐจ๋๋ฐ...
์ฌํผ... HTML, React DOM์ ๋ ์ฌ๋ ค๋ณด๋ผ
<html>
<head>
<body>
<div></div>
<div></div>
</body>
</head>
</html>
<html> ์ด root Node๊ณ
root๊ฐ ์๋๋ผ๋ ์์๋ก root๋ฅผ ๋ง๋ค์ด์ฃผ์ด ํธ๋ฆฌ๋ฅผ ์๊ณ ๋ฆฌ์ฆ์ ํ์ฉํ ์ ์์
(or ์ต์ข
์ ์ผ๋ก <> </>๋ก wrapper์ ๋ง๋ค๋ฉด ๋จ)
์ผ์์ํ/ํ๋ก๊ทธ๋จ์์ ์ ๋ง ๋ง์ด ์ฐ์ด๋ ๊ตฌ์กฐ
Tree๋ ๊ฐ์ง์ ๊ฐ์ ์ ํ์ด ์์
=> ๋๋ฌด ๋ง์ ๊ฐ์ง๊ฐ ๋์ค๋ฉด ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ํ์ฉํ๊ธฐ ์ด๋ ค์
=> ๊ฐ์ง ๊ฐ์์ ์ ํ์ ์ค
ex. ์ด์ง ํธ๋ฆฌ binary tree (๊ฐ์ง 0~2๊ฐ) => (๊ฒ์/์ ๋ ฌ)
๊ฐ๊ฐ์ Node ๋ง๋ค children ๊ฐ์๊ฐ ๋ค ๋ฌ๋ผ์ ์๊ณ ๋ฆฌ์ฆ์ ํต์ผ๋๊ฒ ์ ์ฉํ๊ธฐ ์ด๋ ค์
=> ๋จ์ Tree๊ตฌ์กฐ์์๋ ์ ๋๊ฒ push()ํ๋ ๋๋์ด๋ผ ํน๋ณํ ๊ฒ ์์..ใ
ใ
=> ๊ทธ๋์ ๋ ๋๋ธ๋ํธ๋ฆฌ, AVL ํธ๋ฆฌ, ์ด์ง ํธ๋ฆฌ, ์ด์ง ํ์ ํธ๋ฆฌ ๋ฑ ์ฌ๋ฌ ์ข
๋ฅ๊ฐ ์์
Root
Edge(๋งํฌ)
Leaf nodes (์์ ์๋ Node)
*** Sub Tree ***
Parent Node
Child Node
Siblings (๊ฐ์ ๋ ๋ฒจ)
*** Height ***
Level
class Tree {
constructor(value) {
this.root = new Node(value);
}
}
class Node {
children = [];
constructor(value) {
this.value = value;
}
push(value){
this.children.push(new Node(value));
// new Node(value) ํธ์ํ๋ ์ด์ = ์์๋ children ๊ฐ์ง ์ ์๊ฒ๋
}
}
const tree = new Tree(50);
const tree = new Tree(50);
tree.root.push(1);
tree.root.push(2);
console.log(
tree.root.children,
/*
[
Node { children: [], value: 1 },
Node { children: [], value: 2 }
]
*/
tree.root.children[0].value, // 1
tree.root.children[1].value, // 2
)
tree.root.children[0].push(30);
tree.root.children[1].push(31);
console.log(
tree.root.children[0],
/*
Node {
children: [
Node { children: [], value: 30 }
], value: 1 } Node
*/
tree.root.children[1],
/*
Node {
children: [
Node { children: [], value: 31 }
], value: 2 }
*/
)