WonYong-Jang / algorithm

0 stars 0 forks source link

트리 #26

Open WonYong-Jang opened 5 years ago

WonYong-Jang commented 5 years ago

트리

이진 트리

모든 노드들이 둘 이하의 자식을 가질 때 이를 이진 트리

트리 순회

http://3dmpengines.tistory.com/423 먼저 트리 순회 방법이 있는 이유는 트리는 선형이 아닌 비선형이기 때문에 모든 노드들을 거쳐가기 위한 방법이 필요하게 된다.

수식 트리

https://blog.naver.com/muramura12/220704218849

WonYong-Jang commented 5 years ago

트리의 지름

WonYong-Jang commented 4 years ago

105. Construct Binary Tree from Preorder and Inorder Traversal

preorder , inorder 이용하여 binary tree 구하기 !!!!!!!!!

preorder = [3,9,20,15,7] inorder = [9,3,15,20,7]

=> inorder : 각 서브 트리의 root 가 중간에 나오기 때문에 앞에서 부터 인덱스 별로 hash 화 시켜준다면 서브 트리의 root 기준으로 인덱스가 작은 값은 left child / 큰 값은 right child

=> preorder : root가 처음 나오기 때문에 순차적으로 inorder 의 hash 값을 찾아서 연결한다.

106. Construct Binary Tree from Inorder and Postorder Traversal

postorder , inorder 이용하여 binary tree 구하기 !!!!!!!!!

inorder = [9,3,15,20,7] postorder = [9,15,7,20,3]

풀어보기!!!!!!!!