Algorithm Get the elements of each layer in the tree

알고리듬 Get the elements of each layer in the tree를 알아보겠습니다.

트리 구조에서 각 계층마다 숫자들을 구해보겠습니다.



아래의 트리를 예로 들어봅시다.
1 계층의 값은 1
2 계층의 값은 2, 3
3 계층의 값은 4, 5, 6
4 계층의 값은 7




깊이 우선 탐색 DFS의 전위 순회(Preorder Traversal)를 사용하면 먼저 계층부터 내려가면서 탐색하기 때문에 손쉽게 구할 수 있습니다.

DFS의 설명은 아래 글에서 확인할 수 있습니다.









끝.


카테고리: Algorithm

댓글

이 블로그의 인기 게시물

Python OpenCV 빈 화면 만들기

Python urllib.parse.quote()

Python bytes.fromhex()

Android AVD Ram size change

Forensics .pyc 파일 .py로 복구하기

Android Minimum touch target size

KiCad 시작하기 7 (FreeRoute 사용하기 2)

C++ OpenCV 모폴로지 침식, 팽창

Android Notification with Full Screen

tensorflow tf.expand_dims()