ํฐ์คํ ๋ฆฌ ๋ทฐ
(๊ตฌ)์๋ฃ๊ตฌ์กฐ&์๊ณ ๋ฆฌ์ฆ
์ด์งํธ๋ฆฌ์ ์ํ (Traversal) - ๊น์ด ์ฐ์ ์ํ (DFT)
yeahajeong 2020. 6. 25. 16:12๋ฐ์ํ
๊น์ด ์ฐ์ ์ํ (Depth First Traversal)
- ์ค์ ์ํ (in-order travelsal) : ์ผ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํํ ๋ค ๋ ธ๋ x๋ฅผ ๋ฐฉ๋ฌธ, ๊ทธ๋ฆฌ๊ณ ๋์ ์ค๋ฅธ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํ
- ์ ์ ์ํ (pre-order travelsal) : ๋ ธ๋ x๋ฅผ ๋ฐฉ๋ฌธํ ํ์ ์ผ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํ, ๋ง์ง๋ง์ผ๋ก ์ค๋ฅธ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํ
- ํ์ ์ํ (post-order traversal) : ์ผ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํ, ์ค๋ฅธ์ชฝ ์๋ธํธ๋ฆฌ๋ฅผ ์ํ ํ ๋ง์ง๋ง์ผ๋ก ๋ ธ๋ x๋ฅผ ๋ฐฉ๋ฌธ
class Node:
def __init__(self, item):
self.data = item
self.left = None
self.right = None
def inorder(self):
traversal = []
if self.left:
traversal += self.left.inorder()
traversal.append(self.data)
if self.right:
traversal += self.right.inorder()
return traversal
def preorder(self):
traversal = []
traversal.append(self.data)
if self.left:
traversal += self.left.preorder()
if self.right:
traversal += self.right.preorder()
return traversal
def postorder(self):
traversal = []
if self.left:
traversal += self.left.postorder()
if self.right:
traversal += self.right.postorder()
traversal.append(self.data)
return traversal
class BinaryTree:
def __init__(self, r):
self.root = r
def inorder(self):
if self.root:
return self.root.inorder()
else:
return []
def preorder(self):
if self.root:
return self.root.preorder()
else:
return []
def postorder(self):
if self.root:
return self.root.postorder()
else:
return []
def solution(x):
return 0
๋ฐ์ํ
'(๊ตฌ)์๋ฃ๊ตฌ์กฐ&์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ด์ง ํ์ ํธ๋ฆฌ (Binary Search Trees) (0) | 2020.06.27 |
---|---|
์ด์งํธ๋ฆฌ์ ์ํ (Traversal) - ๋์ด ์ฐ์ ์ํ (BFT) (0) | 2020.06.26 |
์ด์งํธ๋ฆฌ (Binary Trees) (0) | 2020.06.25 |
ํธ๋ฆฌ (Trees) (0) | 2020.06.25 |
์ฐ์ ์์ ํ (Priority Queues) (0) | 2020.06.25 |
๋๊ธ
๊ณต์ง์ฌํญ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
- Total
- Today
- Yesterday
๋งํฌ
TAG
- ๋ถํธ ์๋์์ฑ
- ๊ฒ์ํ๋ง๋ค๊ธฐ
- ์คํ๋ง๋ถํธ ์๋์์ฑ
- ๊ฒ์๋ฌผ์กฐํ
- tomcat์ค์น
- typeAliases
- ์ดํด๋ฆฝ์ค ์ค์น
- ๋ณ๋ช ์ฒ๋ฆฌ
- ์๋ฐ
- ์ดํด๋ฆฝ์ค ํ๊ธ ์ธ์ฝ๋ฉ
- Java
- ๊ฐ๋ฐ
- ์จ๋ฆฌ์์ค
- ๊ฒ์ํ ์ญ์
- ์ ์ฒด๊ฒ์๋ฌผ ์กฐํ
- ์๋ฃ๊ตฌ์กฐ
- ๊ฐ๋ฐํ๊ฒฝ๊ตฌ์ถ
- java ํ๊ฒฝ๋ณ์
- ๊ฒ์ํ ์กฐํ
- ์๊ณ ๋ฆฌ์ฆ
- mysql์ค์น
- java jdk ์ค์น
- ๊ฒ์๋ฌผ ์ญ์
- Algorithm
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
๊ธ ๋ณด๊ดํจ