※잘못 이해한 부분이 있을 수도 있음!
자료구조 종류 맛보기
1. Linked List
어떤 data와 그 다음 data가 연결되어 있는 형태. 리스트의 앞부분에는 해당 data에 대한 내용이 저장되어 있고, 리스트의 뒷부분에는 다음 data의 주소가 저장되어 data들을 연결하는 형태
2. Stack
순차적으로 data가 저장되어 있는 형태. FILO(First In, Last Out)의 특징을 지님
3. Queue
stack과 같이 순차적으로 data가 저장되어 있는 형태. 그러나 First In, First Out이라는 stack과 다른 특징을 지니고 있음
4. Graph
node와 edge를 지니고 있는 형태. tree는 graph에 포함되어 있음
프로그램은 자료구조와 알고리즘으로 구성되어 있음
ex) Max search = array(or linked list) + sequential search
알고리즘
step-by-step procedure for solving computer problems
requirement of algorithm
- input : 0 또는 그 이상의 수의 input이 있어야 함
- output : 최소 한 개의 output이 present되어야 함
- plainness : 원하는 바가 명백해야 함 (the meaning of command should be clear)
- finiteness : 제한된 단계 후 종료해야 함(must be terminated after a limited number of steps) ---- 결과값이 반환되거나 에러가 뜨려면 알고리즘이 종료되어야 하는 것이니까 필요한 성질 중 하나라고 생각됨
- validity(타당성) : 각 instruction은 실행가능해야 함
How to Describe Algorithms
1. Natural language
- 사람이 읽기 쉽다는 장점을 지님.
- 그러나 정확히 명시되지(defined) 않았을 경우 해석이 모호해진다는 단점 또한 지니고 있음.
2. Flow chart
- 직관적이고 이해가 쉽다는 장점을 지님.
- 복잡한 알고리즘에서는 꽤나 복잡해진다는 단점을 지님 -> 교수님이 크게 추천하지는 않는 방식이라 함
3. Pseudo code
가장 추천하는 방식!
- High-level description of algorithm
- 알고리즘 묘사에 효과적이고 알고리즘 묘사에 많이 사용됨.
- More structured representation than natural language
- 프로그래밍 랭귀지보다는 expressive하지 않음
4. Programming language
- 알고리즘을 묘사하는 것에 있어서 가장 정확한 방식
- 그러나 많은 세부사항이 알고리즘을 이해하는 데에 있어서 방해가 될 수 있음(many specifics may interfere with understanding the algorithm)
Abstract Data Type(ADT)
Data type : A set of data and a set of operations
data : {-2, -1, 0 , 1, 2....}
operation : +, -, /, *, %
Abstract Data Type
- Abstractly (mathematically) defined data type
- data 또는 operation이 정의되었지만 그것들을 컴퓨터에서 어떻게 실행될지에 대해서는 정의되지 않음
(what data or perations is defined, but how to implement the data or operations on a computer is undefined)
Definition of ADT
Object
ADT에 속하는 object가 정의됨
Operations
object간의 operations가 정의됨
this operation acts as an interface between the abstract data type and the outside
ADT in Program
C++, Java : class(variable and function)
'private' or 'protected' - prevent the access to internal data
Hierarchical architecture
C : struct
정확도만이 알고리즘의 완성도, 성공도를 나타내는 것이 아님!
1. Execution time measure
- 알고리즘의 실제 실행시간을 측정
- 실제로 실행해야함
- 똑같은 하드웨어 사용
clock_t clock(void);를 사용하여 running time을 계산하는 것과 같은 방식으로 구할 수 있음
2. Complexity analysis
- 직접적인 실행(implementation) 없이 실행시간 분석
- 알고리즘에서 실행된 operation의 수를 측정
- 일반적으로 the number of operations : a fuction of n(n= the number of input data)
pseudo code를 통해 number of operation을 셈
- Time complexity analysis : execution time
number of operation을 계산하여 구함
- Spatial complexity analysis : memory space required for execution
time complexity와 spatial complexity는 서로 반대되는 경향을 보여줌
memory space ↓ → time complexity ↑
=> 이로인해 spatial complexity analysis 사용
Complexity analysis
- the number of peratios performed on the algorithm
- Basic operaions
- Arithmetic (+, -, x, /)
곱하기, 나누기가 더하기, 빼기보다 기본적 복잡도가 높음
- assignment (A[i] = 5))
- comparison (if (A[i] > 5))
- shift operations
- the number of operations T(n) : a funtion of time complexity for the number n of inputs
Example
1.

2.

데이터의 수가 많은 경우 계수가 가장 큰 항이 다른 항들 보다 영향력이 있고 이에 따라 다른 항들을 무시해도 괜찮음
따라서 time complexity function에서 가장 큰 영향을 미치는 항만 고려해도 충분함
Big O Notation
Asymptotic(when n become infinite) number of operations
indicates the upper bound of the function
time complexity in the worst case
worst를 상정해야 좋으므로 해당 notation이 가장 선호됨
Big Ω Notation
indicates the lower bound of the function
time complexity in the best case
Big θ Notation
indicates the lower and upper bound of the function
→ combination of lower and upper
best/ worst case 모두 알 수 있는 경우에 사용됨
Best, Average and Worst Cases
The execution time of the algorithm may vary depending on the input data
- Best case : the fastest execution time = Big Ω Notation
- Average case : the average execution time = Expectation
- Worst case : the slowest execution time = Big O Notation
- Most widely used
- Easy to calculate and may have important meaning depending on the application
Description Principles
1. Constant : capitalized
2. Variable : use lower case letters and use underline to separate words and words
3. Function : use the verb to indicate what the function does
4. 'typedef' : used when creating user-defined data types in C
DataStructure in C
Structure
연산이 호출될 때 데이터 구조와 관련된 데이터, 함수의 매개 변수로 이 구조를 전달
(the data related to the data structure when an operation is called, pass this structure as a parameter of the function)