개념
-
[자료구조] Tree 개념/정의코딩(Coding)/자료구조 2021. 1. 5. 13:26
Tree 트리(Tree)는 하나 이상의 노드들로 구성된 유한집합이다. 트리는 가장 최상위에 존재하는 Root 노드와 그 노드서부터 내려가는 하위노드들의 구성으로 표현된다. 아래 그림을 보자 그림처럼 Tree를 표현하면 위 그림같이 될 것이다. Root노드인 A는 하위 노드인 B,C,D노드가 있고 각각의 하위노드들은 또 자신들만의 하위노드들이 있다. 여기서 A에 대해 subTree는 B노드와 그의 하위 노드들과 C,D노드와 각각의 하위노드들이 될 것이다. Tree 설계 그렇다면 Tree는 어떻게 설계하면 좋을까? 생각해보자 일단 노드 A는 data와 sub-Node를 저장할 Node변수 3개가 필요할 것이다. 그렇다면 아래 그림 처럼 Tree의 노드구조를 설명할 수 있겠다. 자 그럼 문제는 다음이다. 가령..