Basic Data Structures(1)
2016. 3. 19
장 홍 준
From abstract, to discrete
A : B, C
B : C
Contents
• Array
• Tree
- Binary
- General
• Graph
- non-weighted
- weighted
Array
(Data Type) (Name)[Dim_1_Size]…[Dim_k_Size]
vector < vector < … > > (Name)
Tree - Binary
1. Array
1) 2*index : left child, 2*index + 1 : right child
2) left child : index_p, right child : index_q
2. Vector
Vector <Type> a[Size];
a[from].push_back(to);
a[to].push_back(from);
Tree - General
1. Linked List
list <Type> (Name)[Size];
2. Vector
vector <Type> a[Size];
a[from].push_back(to); a[to].push_back(from);
list와 vector 모두 똑같이 사용할 수 있다.
STL <list> example
STL <vector> example
Graph
• 표현법은 트리와 같음.
• Non-weighted의 경우 Adjacent Matrix에 들어가는 value는 constant
• Weighted의 경우, weight.
실습 문제
• N개의 정점, M개의 가중치가 있는 간선의 그래프가 있다.
• N, M, M개의 간선 정보가 주어지면, 입력을 받고 출력을 하자.
- input
3 4
1 2 1
3 4 2
1 3 2
3 2 1
- output
1 : (2, 1), (3, 2)
2 : (1, 1) (3, 1)
3 : (1, 2), (2, 1), (4, 2)
4 : (3, 2)

2. basic data structures(1)