forked from ndb796/Python-Competitive-Programming-Team-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.py
More file actions
33 lines (26 loc) · 1.11 KB
/
Copy pathtree.py
File metadata and controls
33 lines (26 loc) · 1.11 KB
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
31
32
33
''' [ Tree ]
- 트리(자유트리) : 사이클이 없는 연결 그래프
- 자유트리에서 하나의 정점을 루트로 정하면, "루트를 가진 트리"가 되며,
이것을 간단히 '트리'라고 부른다. 이때 정점대신 노드란 용어를 사용한다.
- 이진 트리 : 자식 노드의 갯수(=최대 차수)가 2로 제한되는 트리
- 이진 탐색 트리 : 이진 트리 + (왼쪽자식<부모<오른쪽자식)조건
- 구조에 따라 AVL트리, 완전이진트리, 포화이진트리 등 다양하다.
- 외부 라이브러리 'anytree'를 통해 쉽게 구현이 가능하다.
참고 URL:
https://geonlee.tistory.com/72 (이진탐색트리)
https://blog.naver.com/hunii123/222539583613
https://velog.io/@ash3767/python-Data-Structure
'''
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
class BinaryTree:
def __init__(self, root):
self.root = root
'''
파이썬에서 트리 혹은 그래프는 dictionary를 이용해 구현할 수도 있다.
'''
graph = dict()
graph['parent'] = ('data', 'child')