본문 바로가기

컴퓨터/이론

그래프 이론 in Golang (Depth First Search)

반응형

1.0 그래프 이론과 구현

- 1.1 => Node value와 left, right value의 이해

- 1.2 => Sample input을 기반으로 트리 구현

연습문제1.1: Node value 구현

예제 1.1

- 기본적인 Node의 구현

- 하드코딩 (= 오로지 개념을 위한 구현임)

type Node struct {
value int
   left *Node
   Right *Node
}

four := &Node{
Value: 4,
}
six := &Node{
Value: 6,
}
four.Right = six

연습문제1.2: Node 구현 (Without Hard-coding) [2]

예제 1.2

가로줄 읽는 법

첫번째 숫자 (예: 1): Value of the node

두번째 숫자 (예: -1): Index of left child (-1일 경우 없음)

세번째 숫자 (예: -1): Index of right child (-1일 경우 없음)

Resources

- [1] Graph Theory - Representing Trees in Go Code

- [2] GitHub Repo (Jinhee Han)

 

반응형

'컴퓨터 > 이론' 카테고리의 다른 글

Docker & Kubernetes 노트  (0) 2023.11.11
Generative AI models  (0) 2023.07.17
HTTP vs. WebSocket  (0) 2023.06.19