17
Computer Algorithm 실실 - Backtracking, Greedy Method - Kim Hwan-Hee ([email protected]) 2013. 5. 20. 1

Computer Algorithm 실습 - Backtracking, Greedy Method -

  • Upload
    camdyn

  • View
    192

  • Download
    0

Embed Size (px)

DESCRIPTION

Computer Algorithm 실습 - Backtracking, Greedy Method -. Kim Hwan- Hee ([email protected]) 2013. 5. 20. < 목 차 >. Backtracking( 되추적 ) – Graph Coloring 알고리즘 설명 프로그래밍 실습 Greedy Method( 탐욕적인 방법 ) – Prim Algorith m 알고리즘 설명 프로그래밍 실습 알고리즘 HW #2. 1. Backtracking – Graph Coloring. - PowerPoint PPT Presentation

Citation preview

Page 1: Computer Algorithm  실습 -  Backtracking, Greedy Method -

1

Computer Algorithm 실습- Backtracking, Greedy Method -

Kim Hwan-Hee([email protected])

2013. 5. 20.

Page 2: Computer Algorithm  실습 -  Backtracking, Greedy Method -

2

< 목 차 >

• Backtracking( 되추적 ) – Graph Coloring

1) 알고리즘 설명2) 프로그래밍 실습

• Greedy Method( 탐욕적인 방법 ) – Prim Algorithm

1) 알고리즘 설명2) 프로그래밍 실습

• 알고리즘 HW #2

Page 3: Computer Algorithm  실습 -  Backtracking, Greedy Method -

3

1. Backtracking – Graph Coloring

• Graph Coloring Algorithm Overview1) m 개의 색을 가지고 , 인접한 지역이 같은 색이 되지 않도록 지도에

색칠하는 문제2) 위와 같은 그래프에서 2 가지 색은 불가능3) 3 가지 색은 총 6 가지 방법 가능

Page 4: Computer Algorithm  실습 -  Backtracking, Greedy Method -

4

1. Backtracking – Graph Coloring

• Graph Coloring Algorithm ( 1/2 )1) 입력 : n – 노드의 수 , m – 색깔의 수 , W[i][j] – 이음선 있으면 true, 그렇지 않으면 false2) 출력 : vcolor[i] - i 번째 노드에 할당된 색 (1 ~ m) 이다 .

Page 5: Computer Algorithm  실습 -  Backtracking, Greedy Method -

5

1. Backtracking – Graph Coloring

• Graph Coloring Algorithm ( 2/2 )

Page 6: Computer Algorithm  실습 -  Backtracking, Greedy Method -

6

1. Backtracking – Graph Coloring

• Graph Coloring Programming ( 1/3 )

Page 7: Computer Algorithm  실습 -  Backtracking, Greedy Method -

7

1. Backtracking – Graph Coloring

• Graph Coloring Programming ( 2/3 )

Page 8: Computer Algorithm  실습 -  Backtracking, Greedy Method -

8

1. Backtracking – Graph Coloring

• Graph Coloring Programming ( 3/3 )

Page 9: Computer Algorithm  실습 -  Backtracking, Greedy Method -

9

1. Backtracking – Graph Coloring

• Graph Coloring Result1) 색의 수를 3 가지로 하였을 때의 결과는 다음과 같다 .

Page 10: Computer Algorithm  실습 -  Backtracking, Greedy Method -

10

2. Greedy Method – Prim Algo-rithm

• Prim Algorithm Overview ( 1/2 )1) 문제 : 비방향성 그래프 G = (V,E) 가 주어졌을 때 , F E 를 만족하면서 , (V,F)

가 G 의 MST 가 되는 F 를 찾는 문제 .

2) 그래프의 인접행렬식 표현

3) 추가적으로 nearest[1..n] 과 distance[1..n] 배열 유지① nearest[i] = Y 에 속한 노드 중 vi(V-Y) 에서 가장 가까운 노드의 인덱스 ② distance[i] = vi 와 nearest[i] 를 잇는 이음선의 가중치

Page 11: Computer Algorithm  실습 -  Backtracking, Greedy Method -

11

2. Greedy Method – Prim Algo-rithm• Prim Algorithm Overview ( 2/2 )

1) 그래프의 인접행렬식 표현v1 v2

v3 v4

v5

1

3 3

4

2 5

6

Page 12: Computer Algorithm  실습 -  Backtracking, Greedy Method -

12

2. Greedy Method – Prim Algo-rithm• Prim Algorithm ( 1/2 )

Page 13: Computer Algorithm  실습 -  Backtracking, Greedy Method -

13

2. Greedy Method – Prim Algo-rithm• Prim Algorithm ( 2/2 )

Page 14: Computer Algorithm  실습 -  Backtracking, Greedy Method -

14

2. Greedy Method – Prim Algo-rithm• Prim Programming

Page 15: Computer Algorithm  실습 -  Backtracking, Greedy Method -

15

2. Greedy Method – Prim Algo-rithm• Prim Result

Page 16: Computer Algorithm  실습 -  Backtracking, Greedy Method -

16

3. HW #2

• 앞서 Greedy Method 와 Backtracking Algorithm 을 한 가지씩 살펴보았습니다 .

1) Greedy Method – Prim Algorithm

2) Backtracking – Graph Coloring

• Greedy Method 방법과 Backtracking Algorithm 의 실습을 위해 한 가지씩 프로그래밍을 더 수행하세요 .

1) Greedy Method – Dijkstra Algorithm

2) Backtracking – nQueens Problem ( n = 4 일 때 )

Page 17: Computer Algorithm  실습 -  Backtracking, Greedy Method -

17