트리
-
[자료구조] 트리개발/자료구조와 알고리즘 2022. 1. 26. 02:03
트리 단순 선형 자료구조에서는 계층을 나타내기가 어렵다. 따라서 계층적 자료구조를 만들기 위해서 트리를 생각했다. 값을 가지는 노드와, 노드 사이를 잇는 간선으로 이루어져 있으며, 부모 - 자식 관계를 가진다. 트리를 그림으로 나타내면 위와 같다. 여기서 A - B, C, D의 관계를 부모 - 자식 관계라 하며, 마찬가지로 B - E, F의 관계도 부모 - 자식 관계이다. 가장 위에 있는 노드인 A를 루트(Root)노드라 하고, 자식이 없는 노드들(E, F, C, G)를 리프(Leaf)노드라 한다. 위의 트리는 3개의 층으로 되어있는데, 이를 높이가 3인 트리라고 한다. 트리는 서브트리로 나눌 수 있다. 이렇게 나누면 B와 D는 각각의 서브트리에서 루트노드가 된다. 트리의 자식이 연결되어 싸이클이 생기면..