2. basic data structures(1)

10
Basic Data Structures(1) 2016. 3. 19 장 장 장

Transcript of 2. basic data structures(1)

Page 1: 2. basic data structures(1)

Basic Data Structures(1)

2016. 3. 19장 홍 준

Page 2: 2. basic data structures(1)

From abstract, to discrete

A : B, CB : C

Page 3: 2. basic data structures(1)

Contents• Array

• Tree- Binary- General

• Graph- non-weighted- weighted

Page 4: 2. basic data structures(1)

Array(Data Type) (Name)[Dim_1_Size]…[Dim_k_Size]

vector < vector < … > > (Name)

Page 5: 2. basic data structures(1)

Tree - Binary1. Array1) 2*index : left child, 2*index + 1 : right child2) left child : index_p, right child : index_q

2. VectorVector <Type> a[Size];a[from].push_back(to);a[to].push_back(from);

Page 6: 2. basic data structures(1)

Tree - General1. Linked Listlist <Type> (Name)[Size];

2. Vectorvector <Type> a[Size];

a[from].push_back(to); a[to].push_back(from);list 와 vector 모두 똑같이 사용할 수 있다 .

Page 7: 2. basic data structures(1)

STL <list> example

Page 8: 2. basic data structures(1)

STL <vector> example

Page 9: 2. basic data structures(1)

Graph• 표현법은 트리와 같음 .

• Non-weighted 의 경우 Adjacent Matrix 에 들어가는 value 는 constant

• Weighted 의 경우 , weight.

Page 10: 2. basic data structures(1)

실습 문제• N 개의 정점 , M 개의 가중치가 있는 간선의 그래프가 있다 .• N, M, M 개의 간선 정보가 주어지면 , 입력을 받고 출력을 하자 .

- input3 41 2 13 4 21 3 23 2 1

- output1 : (2, 1), (3, 2)2 : (1, 1) (3, 1)3 : (1, 2), (2, 1), (4, 2)4 : (3, 2)