일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- cURL
- java
- 이진탐색트리
- 백트래킹
- Python
- 2P1L
- 자료형
- 소행성
- dictionary
- 딕셔너리
- 벡터 해석
- 미분 방정식
- 파이썬
- Class
- 선적분
- 코드업
- BST
- 신경망
- 딥러닝
- 피보나치 수열
- auto-encoder
- 함수
- 델
- 최단 경로
- 벡터해석
- 강화학습
- 계단 오르기
- Asteroid RL
- 자바
- 회로이론
- Today
- Total
Zeta Oph's Study
[Data Structure (Java)] Tree (1) - Binary Tree 본문
https://crane206265.tistory.com/80
[Data Structure (Java)] Iterator
https://crane206265.tistory.com/79 [Data Structure (Java)] Listhttps://crane206265.tistory.com/78 [Data Structure (Java)] Stackhttps://crane206265.tistory.com/76 [Data Structure (Java)] SLL (Singly Linked List)https://crane206265.tistory.com/75 [Data S
crane206265.tistory.com
드디어 Tree입니다. 생각보다 간단하면서도, 생각보다 많이 복잡하더라고요.
Tree
: a set of nodes storing elements hierarchically (*hierarchical : 계층적인)
- parent-child relationship between nodes
- each element has a parent : except - root (topmost node)
- each element has zero or more children
Terminology
- root : node without parent
- internal node : node with at least one child
- external node : node without children (leaf)
- depth of a node : # of edges from the root to the node
- height of a tree : maximum # of links on any path from root to a leaf
-> if single node : height = 0
- ==> empty tree : height = -1
- subtree : tree consisting of a node and ALL the descendants
- sibling : have the same parent node
* order of tree : usually) left to right for siblings, top to bottom
Binary Tree
: tree that its every node has at most 2 children
- each child node is labeled as being either a 'left child' or a 'right child'
- a left child precedes a right child in the oreder of a chlidren of a node
converting general tree -> binary tree :
Left-Child-Right-Sibling (LCRS) representation
- root : same
- leftmost child -> left-child
- siblings of left child (at general tree : horizontal) -> right-children (at binary tree : "rotate 45 deg")
level $d$ : set of all nodes at the same depth $d$
ex) - level $0$ : root
- level $d$ : at most $2^d$ nodes
==> $n$ : # of nodes / $h$ : height
# of nodes : $\mathbf{h+1 \leq n \leq} 1 + 2 + 2^2 + \cdots + 2^h = \mathbf{2^{h+1} - 1}$
# of external nodes : $1 \leq n_E \leq 2^h$
# of internal nodes : $h \leq n_I \leq 1 + 2 + \cdots + 2^{h-1} = 2^h-1$
how to index the nodes?
"Level-Numbering" : Numbering Nodes
- root : index = $0$
- left child of a node $i$ : index = $2i+1$
- right child of a node $i$ : index = $2i+2$
it is possible to skip index
-> advantage : easy to convert tree <-> array with arithmetic operations
-> disadvantage : memory waste(empty cells) depending on the shape of a tree
'프로그래밍 > Java' 카테고리의 다른 글
[Data Structure (Java)] Tree (3) - Binary Search Tree (1) | 2024.06.01 |
---|---|
[Data Structure (Java)] Tree (2) - Tree Traversal Algorithms (1) | 2024.05.13 |
[Data Structure (Java)] Iterator (1) | 2024.05.12 |
[Data Structure (Java)] List & Dynamic Array (3) | 2024.05.11 |
[Data Structure (Java)] Queue (1) | 2024.05.09 |