SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
3
4
5
6
7
9
10
11
float ABC(float a, float b, float c)
{
return a + b + b * c + (a + b - c) / (a + b) + 4.0;
}
12
float Sum(float* a, const int n)
{
float s = 0;
for (int i = 0; i < n; i++)
s += a[i];
return s;
}
float Rsum(float* a, const int n)
{
if (n <= 0) return 0;
else return (Rsum(a, n - 1) + a[n - 1]);
}
13
14
15
16
17
18
19
float Sum(float* a, const int n)
1 {
2 float s = 0;
3 for (int i = 0; i < n; i++)
4 s += a[i];
5 return s;
6 }
행 번호 s/e 빈도 단계 수
1 0 0 0
2 1 1 1
3 1 𝑛 + 1 𝑛 + 1
4 1 𝑛 𝑛
5 1 1 1
6 0 1 0
총 단계 수 2𝑛 + 3
s/e : 실행당 단계 수 (Step per Execution)
행 번호 s/e
빈도 단계 수
𝑛 = 0 𝑛 > 0 𝑛 = 0 𝑛 > 0
1 0 1 1 0 0
2(a) 1 1 1 1 1
2(b) 1 1 0 1 0
3 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 0 1 0 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1)
4 0 1 1 0 0
총 단계 수 2 2 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1)
20
float Rsum(float* a, const int n)
1 {
2 if (n <= 0) return 0;
3 else return (Rsum(a, n - 1) + a[n - 1]);
4 }
s/e : 실행당 단계 수 (Step per Execution)
21
22
void Add(int** a, int** b, int** c, int m, int n)
1 {
2 for (int i = 0; i < m; i++)
3 for (int j = 0; j < n; j++)
4 c[i][j] = a[i][j] + b[i][j];
5 }
행 번호 s/e 빈도 단계 수
1 0 0 0
2 1 𝑚 + 1 𝑚 + 1
3 1 𝑚(𝑛 + 1) 𝑚𝑛 + 𝑚
4 1 𝑚𝑛 𝑚𝑛
5 0 1 0
총 단계 수 2𝑚𝑛 + 2𝑚 + 1
s/e : 실행당 단계 수 (Step per Execution)
23
24
25
26
27
28
float Sum(float* a, const int n)
1 {
2 float s = 0;
3 for (int i = 0; i < n; i++)
4 s += a[i];
5 return s;
6 }
행 번호 s/e 빈도 단계 수
1 0 0 Θ(0)
2 1 1 Θ(1)
3 1 𝑛 + 1 Θ(𝑛)
4 1 𝑛 Θ(𝑛)
5 1 1 Θ(1)
6 0 1 Θ(0)
𝑡 𝑆𝑢𝑚 𝑛 = Θ(max
1≤𝑖≤6
{𝑔𝑖 𝑛 }) = Θ(𝑛)
s/e : 실행당 단계 수 (Step per Execution)
행 번호 s/e
빈도 단계 수
𝑛 = 0 𝑛 > 0 𝑛 = 0 𝑛 > 0
1 0 1 1 0 Θ(0)
2(a) 1 1 1 1 Θ(1)
2(b) 1 1 0 1 Θ(0)
3 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 0 1 0 Θ(1 + 𝑡 𝑅𝑠𝑢𝑚 𝑛 − 1 )
4 0 1 1 0 Θ(0)
𝑡 𝑅𝑠𝑢𝑚 𝑛 = 2 Θ(1 + 𝑡 𝑅𝑠𝑢𝑚 𝑛 − 1 )
29
float Rsum(float* a, const int n)
1 {
2 if (n <= 0) return 0;
3 else return (Rsum(a, n - 1) + a[n - 1]);
4 }
s/e : 실행당 단계 수 (Step per Execution)
30
void Add(int** a, int** b, int** c, int m, int n)
1 {
2 for (int i = 0; i < m; i++)
3 for (int j = 0; j < n; j++)
4 c[i][j] = a[i][j] + b[i][j];
5 }
행 번호 s/e 빈도 단계 수
1 0 0 Θ(0)
2 1 Θ(𝑚) Θ(𝑚)
3 1 Θ(𝑚𝑛) Θ(𝑚𝑛)
4 1 Θ(𝑚𝑛) Θ(𝑚𝑛)
5 0 1 Θ(0)
총 단계 수 Θ(𝑚𝑛)
s/e : 실행당 단계 수 (Step per Execution)
31
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
값이 정렬된 배열이 있을 때, Best Case는
찾는 값이 middle에 바로 있는 경우(9를 검색)
2 5 9 11 15 18
2 5 11 15 189
left
(0)
right
(5)
middle
(0+5)/2=2.5≈2
이 때, 시간 복잡도는 𝑂(1)!
x = 9, a[middle] = a[2] = 9이므로
9가 있는 위치 2를 반환
32
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
Worst Case는 배열에 없는 값을 검색할 때
(24를 검색)
2 5 11 15 189
left
(0)
right
(5)
middle
(0+5)/2=2.5≈2
x = 24, a[middle] = a[2] = 9이므로
left를 3으로 바꾼 뒤 다시 수행
33
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 11 189 15
left
(3)
right
(5)
middle
(3+5)/2=4
x = 24, a[middle] = a[4] = 15이므로
left를 5로 바꾼 뒤 다시 수행
34
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 119 15 18
left = right
(5)
middle
(5+5)/2=5
x = 24, a[middle] = a[5] = 18이므로
left를 6로 바꾼 뒤 다시 수행
하지만, while (left <= right) 문에서
left = 6, right = 5이므로 while (false),
while 문을 빠져나오게 되어 -1을 반환
이 때, 시간 복잡도는?
35
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n – 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle – 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 119 15 18
2 5 11 189 15
2 5 11 15 189
시간 복잡도 계산의 핵심은 “while 문이 얼마나 반복되었는가?”
부분이 얼마나 많이 수행되었느냐가 관건
부분은 상수 시간에 수행되므로 𝑂(1)
left right
𝑇 𝑛
left right
𝑇 𝑛/2
𝑇 𝑛/4
left = right
+𝑂(1)
+𝑂(1)
따라서, 시간 복잡도는
𝑇 𝑛 = 𝑇
𝑛
2
+ 𝑂 1 !
36
𝑇 𝑛 = 𝑇
𝑛
2
+ 𝑂 1
= 𝑇
𝑛
22
+ 2𝑂 1
= ⋯
= 𝑇
𝑛
2 𝑘
+ 𝑘𝑂(1)
𝑛 = 2 𝑘
, 𝑇 1 = 𝑂(1)라면
∴ 𝑇 𝑛 = 𝑇 1 + 𝑘𝑂 1
= 𝑘 + 1 𝑂(1)
𝑛 = 2 𝑘
이므로 𝑘 = log2 𝑛
∴ 𝑇 𝑛 = log2 𝑛 + 1 𝑂 1
= 𝑂 log2 𝑛 = 𝑂(log 𝑛)
37
https://en.wikipedia.org/wiki/Big_O_notation
http://bigocheatsheet.com/
38
http://bigocheatsheet.com/
39
http://bigocheatsheet.com/
40
http://bigocheatsheet.com/

Mais conteúdo relacionado

Mais procurados

Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Circulus
 
2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자Circulus
 
[KOSSA] C++ Programming - 13th Study - exception handling
[KOSSA] C++ Programming - 13th Study - exception handling[KOSSA] C++ Programming - 13th Study - exception handling
[KOSSA] C++ Programming - 13th Study - exception handlingSeok-joon Yun
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 명신 김
 
2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdfkd19h
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준Seok-joon Yun
 
6장 표현식 및 문장
6장 표현식 및 문장6장 표현식 및 문장
6장 표현식 및 문장재정 이
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...Seok-joon Yun
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...Seok-joon Yun
 
하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2Kwang Yul Seo
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsSeok-joon Yun
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기scor7910
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...Seok-joon Yun
 
자료구조 Project1
자료구조 Project1자료구조 Project1
자료구조 Project1KoChungWook
 
Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Circulus
 

Mais procurados (20)

Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리
 
2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자
 
[KOSSA] C++ Programming - 13th Study - exception handling
[KOSSA] C++ Programming - 13th Study - exception handling[KOSSA] C++ Programming - 13th Study - exception handling
[KOSSA] C++ Programming - 13th Study - exception handling
 
4. loop
4. loop4. loop
4. loop
 
Ch11
Ch11Ch11
Ch11
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
 
이산치2번
이산치2번이산치2번
이산치2번
 
2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf
 
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
[C++ Korea] Effective Modern C++ MVA item 8 Prefer nullptr to 0 and null +윤석준
 
6장 표현식 및 문장
6장 표현식 및 문장6장 표현식 및 문장
6장 표현식 및 문장
 
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
 
하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2하스켈 프로그래밍 입문 2
하스켈 프로그래밍 입문 2
 
픽킹
픽킹픽킹
픽킹
 
C++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threadsC++ Concurrency in Action 9-2 Interrupting threads
C++ Concurrency in Action 9-2 Interrupting threads
 
어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기어플 개발자의 서버개발 삽질기
어플 개발자의 서버개발 삽질기
 
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
[C++ Korea] Effective Modern C++ MVA item 9 Prefer alias declarations to type...
 
픽킹
픽킹픽킹
픽킹
 
자료구조 Project1
자료구조 Project1자료구조 Project1
자료구조 Project1
 
Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저
 

Destaque

[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기Chris Ohk
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features SummaryChris Ohk
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th StudyChris Ohk
 
게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법Chris Ohk
 
2013 C++ Study For Students #1
2013 C++ Study For Students #12013 C++ Study For Students #1
2013 C++ Study For Students #1Chris Ohk
 
2nd ignite masan 이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이
2nd ignite masan   이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이2nd ignite masan   이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이
2nd ignite masan 이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이Ignite Masan
 
C++ Programming - 9th Study
C++ Programming - 9th StudyC++ Programming - 9th Study
C++ Programming - 9th StudyChris Ohk
 
C++ Programming - 8th Study
C++ Programming - 8th StudyC++ Programming - 8th Study
C++ Programming - 8th StudyChris Ohk
 
C++ Programming - 13th Study
C++ Programming - 13th StudyC++ Programming - 13th Study
C++ Programming - 13th StudyChris Ohk
 
C++ Programming - 10th Study
C++ Programming - 10th StudyC++ Programming - 10th Study
C++ Programming - 10th StudyChris Ohk
 
스크래치와 역사
스크래치와 역사스크래치와 역사
스크래치와 역사Seung Joon Choi
 
C++ Programming - 7th Study
C++ Programming - 7th StudyC++ Programming - 7th Study
C++ Programming - 7th StudyChris Ohk
 
기본 회전 공식
기본 회전 공식 기본 회전 공식
기본 회전 공식 cancan21st
 
C++ Programming - 12th Study
C++ Programming - 12th StudyC++ Programming - 12th Study
C++ Programming - 12th StudyChris Ohk
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th StudyChris Ohk
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd StudyChris Ohk
 
[0611 박민근] 신입 게임 개발자가 알아야 할 것들
[0611 박민근] 신입 게임 개발자가 알아야 할 것들[0611 박민근] 신입 게임 개발자가 알아야 할 것들
[0611 박민근] 신입 게임 개발자가 알아야 할 것들MinGeun Park
 

Destaque (20)

[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
[C++ Korea 3rd Seminar] 새 C++은 새 Visual Studio에, 좌충우돌 마이그레이션 이야기
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
 
C++ Programming - 14th Study
C++ Programming - 14th StudyC++ Programming - 14th Study
C++ Programming - 14th Study
 
게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법게임 프로그래밍 기초 공부법
게임 프로그래밍 기초 공부법
 
2013 C++ Study For Students #1
2013 C++ Study For Students #12013 C++ Study For Students #1
2013 C++ Study For Students #1
 
Id142 plan
Id142 planId142 plan
Id142 plan
 
2nd ignite masan 이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이
2nd ignite masan   이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이2nd ignite masan   이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이
2nd ignite masan 이그나이트마산 09 설미정_ 기부, 기발함과 발칙함사이
 
C++ Programming - 9th Study
C++ Programming - 9th StudyC++ Programming - 9th Study
C++ Programming - 9th Study
 
C++ Programming - 8th Study
C++ Programming - 8th StudyC++ Programming - 8th Study
C++ Programming - 8th Study
 
C++ Programming - 13th Study
C++ Programming - 13th StudyC++ Programming - 13th Study
C++ Programming - 13th Study
 
C++ Programming - 10th Study
C++ Programming - 10th StudyC++ Programming - 10th Study
C++ Programming - 10th Study
 
스크래치와 역사
스크래치와 역사스크래치와 역사
스크래치와 역사
 
Shader Driven
Shader DrivenShader Driven
Shader Driven
 
C++ Programming - 7th Study
C++ Programming - 7th StudyC++ Programming - 7th Study
C++ Programming - 7th Study
 
Mesh slice 1
Mesh slice 1Mesh slice 1
Mesh slice 1
 
기본 회전 공식
기본 회전 공식 기본 회전 공식
기본 회전 공식
 
C++ Programming - 12th Study
C++ Programming - 12th StudyC++ Programming - 12th Study
C++ Programming - 12th Study
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
[0611 박민근] 신입 게임 개발자가 알아야 할 것들
[0611 박민근] 신입 게임 개발자가 알아야 할 것들[0611 박민근] 신입 게임 개발자가 알아야 할 것들
[0611 박민근] 신입 게임 개발자가 알아야 할 것들
 

Semelhante a Data Structure - 1st Study

2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdfkd19h
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdfjinwookhong
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조영기 김
 
함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게Gyooha Kim
 
2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdfjinwookhong
 
Project#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpProject#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpKimjeongmoo
 
Spherical Harmonics.pdf
Spherical Harmonics.pdfSpherical Harmonics.pdf
Spherical Harmonics.pdfBongseok Cho
 
자료구조5보고서
자료구조5보고서자료구조5보고서
자료구조5보고서KimChangHoen
 
이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3pkok15
 
[KOSSA] C++ Programming - 15th Study - STL #1
[KOSSA] C++ Programming - 15th Study - STL #1[KOSSA] C++ Programming - 15th Study - STL #1
[KOSSA] C++ Programming - 15th Study - STL #1Seok-joon Yun
 
2012 Ds D0 01 Pdf
2012 Ds D0 01 Pdf2012 Ds D0 01 Pdf
2012 Ds D0 01 Pdfkd19h
 
2012 Ds D0 01
2012 Ds D0 012012 Ds D0 01
2012 Ds D0 01chl132435
 
이산치7보고서
이산치7보고서이산치7보고서
이산치7보고서KimChangHoen
 
Tensorflow regression 텐서플로우 회귀
Tensorflow regression 텐서플로우 회귀Tensorflow regression 텐서플로우 회귀
Tensorflow regression 텐서플로우 회귀beom kyun choi
 
이산수학 C1 프로젝트 5
이산수학 C1 프로젝트 5이산수학 C1 프로젝트 5
이산수학 C1 프로젝트 5pkok15
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array웅식 전
 

Semelhante a Data Structure - 1st Study (20)

2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf
 
알고리즘과 자료구조
알고리즘과 자료구조알고리즘과 자료구조
알고리즘과 자료구조
 
함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게함수형 프로그래밍? 그래서 어떻게
함수형 프로그래밍? 그래서 어떻게
 
2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf2012 Dm A0 02 Pdf
2012 Dm A0 02 Pdf
 
Project#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 HwpProject#5 최단거리 찾기 D0 Hwp
Project#5 최단거리 찾기 D0 Hwp
 
Spherical Harmonics.pdf
Spherical Harmonics.pdfSpherical Harmonics.pdf
Spherical Harmonics.pdf
 
자료구조5보고서
자료구조5보고서자료구조5보고서
자료구조5보고서
 
BOJ4743
BOJ4743BOJ4743
BOJ4743
 
이산수학03
이산수학03이산수학03
이산수학03
 
Fp basic-kotlin
Fp basic-kotlinFp basic-kotlin
Fp basic-kotlin
 
이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3이산수학 C1 프로젝트 3
이산수학 C1 프로젝트 3
 
[KOSSA] C++ Programming - 15th Study - STL #1
[KOSSA] C++ Programming - 15th Study - STL #1[KOSSA] C++ Programming - 15th Study - STL #1
[KOSSA] C++ Programming - 15th Study - STL #1
 
2012 Ds D0 01 Pdf
2012 Ds D0 01 Pdf2012 Ds D0 01 Pdf
2012 Ds D0 01 Pdf
 
2012 Ds D0 01
2012 Ds D0 012012 Ds D0 01
2012 Ds D0 01
 
이산치7보고서
이산치7보고서이산치7보고서
이산치7보고서
 
Tensorflow regression 텐서플로우 회귀
Tensorflow regression 텐서플로우 회귀Tensorflow regression 텐서플로우 회귀
Tensorflow regression 텐서플로우 회귀
 
이산수학 C1 프로젝트 5
이산수학 C1 프로젝트 5이산수학 C1 프로젝트 5
이산수학 C1 프로젝트 5
 
자료구조02
자료구조02자료구조02
자료구조02
 
12 1. multi-dimensional array
12 1. multi-dimensional array12 1. multi-dimensional array
12 1. multi-dimensional array
 

Mais de Chris Ohk

인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍Chris Ohk
 
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들Chris Ohk
 
Momenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStoneMomenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStoneChris Ohk
 
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기Chris Ohk
 
Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2Chris Ohk
 
Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1Chris Ohk
 
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021Chris Ohk
 
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021Chris Ohk
 
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020Chris Ohk
 
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017Chris Ohk
 
Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015Chris Ohk
 
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Chris Ohk
 
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기Chris Ohk
 
[RLKorea] <하스스톤> 강화학습 환경 개발기
[RLKorea] <하스스톤> 강화학습 환경 개발기[RLKorea] <하스스톤> 강화학습 환경 개발기
[RLKorea] <하스스톤> 강화학습 환경 개발기Chris Ohk
 
[NDC 2019] 하스스톤 강화학습 환경 개발기
[NDC 2019] 하스스톤 강화학습 환경 개발기[NDC 2019] 하스스톤 강화학습 환경 개발기
[NDC 2019] 하스스톤 강화학습 환경 개발기Chris Ohk
 
C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features SummaryChris Ohk
 
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지Chris Ohk
 
디미고 특강 - 개발을 시작하려는 여러분에게
디미고 특강 - 개발을 시작하려는 여러분에게디미고 특강 - 개발을 시작하려는 여러분에게
디미고 특강 - 개발을 시작하려는 여러분에게Chris Ohk
 
청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기Chris Ohk
 
[NDC 2018] 유체역학 엔진 개발기
[NDC 2018] 유체역학 엔진 개발기[NDC 2018] 유체역학 엔진 개발기
[NDC 2018] 유체역학 엔진 개발기Chris Ohk
 

Mais de Chris Ohk (20)

인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
 
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들
고려대학교 컴퓨터학과 특강 - 대학생 때 알았더라면 좋았을 것들
 
Momenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStoneMomenti Seminar - 5 Years of RosettaStone
Momenti Seminar - 5 Years of RosettaStone
 
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
선린인터넷고등학교 2021 알고리즘 컨퍼런스 - Rust로 알고리즘 문제 풀어보기
 
Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2Momenti Seminar - A Tour of Rust, Part 2
Momenti Seminar - A Tour of Rust, Part 2
 
Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1Momenti Seminar - A Tour of Rust, Part 1
Momenti Seminar - A Tour of Rust, Part 1
 
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
Evolving Reinforcement Learning Algorithms, JD. Co-Reyes et al, 2021
 
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
Adversarially Guided Actor-Critic, Y. Flet-Berliac et al, 2021
 
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
Agent57: Outperforming the Atari Human Benchmark, Badia, A. P. et al, 2020
 
Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017Proximal Policy Optimization Algorithms, Schulman et al, 2017
Proximal Policy Optimization Algorithms, Schulman et al, 2017
 
Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015Trust Region Policy Optimization, Schulman et al, 2015
Trust Region Policy Optimization, Schulman et al, 2015
 
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015
 
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기
GDG Gwangju DevFest 2019 - <하스스톤> 강화학습 환경 개발기
 
[RLKorea] <하스스톤> 강화학습 환경 개발기
[RLKorea] <하스스톤> 강화학습 환경 개발기[RLKorea] <하스스톤> 강화학습 환경 개발기
[RLKorea] <하스스톤> 강화학습 환경 개발기
 
[NDC 2019] 하스스톤 강화학습 환경 개발기
[NDC 2019] 하스스톤 강화학습 환경 개발기[NDC 2019] 하스스톤 강화학습 환경 개발기
[NDC 2019] 하스스톤 강화학습 환경 개발기
 
C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features Summary
 
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지
[델리만주] 대학원 캐슬 - 석사에서 게임 프로그래머까지
 
디미고 특강 - 개발을 시작하려는 여러분에게
디미고 특강 - 개발을 시작하려는 여러분에게디미고 특강 - 개발을 시작하려는 여러분에게
디미고 특강 - 개발을 시작하려는 여러분에게
 
청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기청강대 특강 - 프로젝트 제대로 해보기
청강대 특강 - 프로젝트 제대로 해보기
 
[NDC 2018] 유체역학 엔진 개발기
[NDC 2018] 유체역학 엔진 개발기[NDC 2018] 유체역학 엔진 개발기
[NDC 2018] 유체역학 엔진 개발기
 

Data Structure - 1st Study

  • 1.
  • 2.
  • 3. 3
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. 7
  • 8.
  • 9. 9
  • 10. 10
  • 11. 11 float ABC(float a, float b, float c) { return a + b + b * c + (a + b - c) / (a + b) + 4.0; }
  • 12. 12 float Sum(float* a, const int n) { float s = 0; for (int i = 0; i < n; i++) s += a[i]; return s; }
  • 13. float Rsum(float* a, const int n) { if (n <= 0) return 0; else return (Rsum(a, n - 1) + a[n - 1]); } 13
  • 14. 14
  • 15. 15
  • 16. 16
  • 17. 17
  • 18. 18
  • 19. 19 float Sum(float* a, const int n) 1 { 2 float s = 0; 3 for (int i = 0; i < n; i++) 4 s += a[i]; 5 return s; 6 } 행 번호 s/e 빈도 단계 수 1 0 0 0 2 1 1 1 3 1 𝑛 + 1 𝑛 + 1 4 1 𝑛 𝑛 5 1 1 1 6 0 1 0 총 단계 수 2𝑛 + 3 s/e : 실행당 단계 수 (Step per Execution)
  • 20. 행 번호 s/e 빈도 단계 수 𝑛 = 0 𝑛 > 0 𝑛 = 0 𝑛 > 0 1 0 1 1 0 0 2(a) 1 1 1 1 1 2(b) 1 1 0 1 0 3 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 0 1 0 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 4 0 1 1 0 0 총 단계 수 2 2 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 20 float Rsum(float* a, const int n) 1 { 2 if (n <= 0) return 0; 3 else return (Rsum(a, n - 1) + a[n - 1]); 4 } s/e : 실행당 단계 수 (Step per Execution)
  • 21. 21
  • 22. 22 void Add(int** a, int** b, int** c, int m, int n) 1 { 2 for (int i = 0; i < m; i++) 3 for (int j = 0; j < n; j++) 4 c[i][j] = a[i][j] + b[i][j]; 5 } 행 번호 s/e 빈도 단계 수 1 0 0 0 2 1 𝑚 + 1 𝑚 + 1 3 1 𝑚(𝑛 + 1) 𝑚𝑛 + 𝑚 4 1 𝑚𝑛 𝑚𝑛 5 0 1 0 총 단계 수 2𝑚𝑛 + 2𝑚 + 1 s/e : 실행당 단계 수 (Step per Execution)
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27
  • 28. 28 float Sum(float* a, const int n) 1 { 2 float s = 0; 3 for (int i = 0; i < n; i++) 4 s += a[i]; 5 return s; 6 } 행 번호 s/e 빈도 단계 수 1 0 0 Θ(0) 2 1 1 Θ(1) 3 1 𝑛 + 1 Θ(𝑛) 4 1 𝑛 Θ(𝑛) 5 1 1 Θ(1) 6 0 1 Θ(0) 𝑡 𝑆𝑢𝑚 𝑛 = Θ(max 1≤𝑖≤6 {𝑔𝑖 𝑛 }) = Θ(𝑛) s/e : 실행당 단계 수 (Step per Execution)
  • 29. 행 번호 s/e 빈도 단계 수 𝑛 = 0 𝑛 > 0 𝑛 = 0 𝑛 > 0 1 0 1 1 0 Θ(0) 2(a) 1 1 1 1 Θ(1) 2(b) 1 1 0 1 Θ(0) 3 1 + 𝑡 𝑅𝑠𝑢𝑚(𝑛 − 1) 0 1 0 Θ(1 + 𝑡 𝑅𝑠𝑢𝑚 𝑛 − 1 ) 4 0 1 1 0 Θ(0) 𝑡 𝑅𝑠𝑢𝑚 𝑛 = 2 Θ(1 + 𝑡 𝑅𝑠𝑢𝑚 𝑛 − 1 ) 29 float Rsum(float* a, const int n) 1 { 2 if (n <= 0) return 0; 3 else return (Rsum(a, n - 1) + a[n - 1]); 4 } s/e : 실행당 단계 수 (Step per Execution)
  • 30. 30 void Add(int** a, int** b, int** c, int m, int n) 1 { 2 for (int i = 0; i < m; i++) 3 for (int j = 0; j < n; j++) 4 c[i][j] = a[i][j] + b[i][j]; 5 } 행 번호 s/e 빈도 단계 수 1 0 0 Θ(0) 2 1 Θ(𝑚) Θ(𝑚) 3 1 Θ(𝑚𝑛) Θ(𝑚𝑛) 4 1 Θ(𝑚𝑛) Θ(𝑚𝑛) 5 0 1 Θ(0) 총 단계 수 Θ(𝑚𝑛) s/e : 실행당 단계 수 (Step per Execution)
  • 31. 31 int BinarySearch(int* a, const int x, const int n) { // Search the sorted array a[0], ... , a[n-1] for x. int left = 0, right = n - 1; while (left <= right) { // There are more elements int middle = (left + right) / 2; if (x < a[middle]) right = middle - 1; else if (x > a[middle]) left = middle + 1; else return middle; } // End of while return -1; // Not found } 값이 정렬된 배열이 있을 때, Best Case는 찾는 값이 middle에 바로 있는 경우(9를 검색) 2 5 9 11 15 18 2 5 11 15 189 left (0) right (5) middle (0+5)/2=2.5≈2 이 때, 시간 복잡도는 𝑂(1)! x = 9, a[middle] = a[2] = 9이므로 9가 있는 위치 2를 반환
  • 32. 32 int BinarySearch(int* a, const int x, const int n) { // Search the sorted array a[0], ... , a[n-1] for x. int left = 0, right = n - 1; while (left <= right) { // There are more elements int middle = (left + right) / 2; if (x < a[middle]) right = middle - 1; else if (x > a[middle]) left = middle + 1; else return middle; } // End of while return -1; // Not found } Worst Case는 배열에 없는 값을 검색할 때 (24를 검색) 2 5 11 15 189 left (0) right (5) middle (0+5)/2=2.5≈2 x = 24, a[middle] = a[2] = 9이므로 left를 3으로 바꾼 뒤 다시 수행
  • 33. 33 int BinarySearch(int* a, const int x, const int n) { // Search the sorted array a[0], ... , a[n-1] for x. int left = 0, right = n - 1; while (left <= right) { // There are more elements int middle = (left + right) / 2; if (x < a[middle]) right = middle - 1; else if (x > a[middle]) left = middle + 1; else return middle; } // End of while return -1; // Not found } 2 5 11 189 15 left (3) right (5) middle (3+5)/2=4 x = 24, a[middle] = a[4] = 15이므로 left를 5로 바꾼 뒤 다시 수행
  • 34. 34 int BinarySearch(int* a, const int x, const int n) { // Search the sorted array a[0], ... , a[n-1] for x. int left = 0, right = n - 1; while (left <= right) { // There are more elements int middle = (left + right) / 2; if (x < a[middle]) right = middle - 1; else if (x > a[middle]) left = middle + 1; else return middle; } // End of while return -1; // Not found } 2 5 119 15 18 left = right (5) middle (5+5)/2=5 x = 24, a[middle] = a[5] = 18이므로 left를 6로 바꾼 뒤 다시 수행 하지만, while (left <= right) 문에서 left = 6, right = 5이므로 while (false), while 문을 빠져나오게 되어 -1을 반환 이 때, 시간 복잡도는?
  • 35. 35 int BinarySearch(int* a, const int x, const int n) { // Search the sorted array a[0], ... , a[n-1] for x. int left = 0, right = n – 1; while (left <= right) { // There are more elements int middle = (left + right) / 2; if (x < a[middle]) right = middle – 1; else if (x > a[middle]) left = middle + 1; else return middle; } // End of while return -1; // Not found } 2 5 119 15 18 2 5 11 189 15 2 5 11 15 189 시간 복잡도 계산의 핵심은 “while 문이 얼마나 반복되었는가?” 부분이 얼마나 많이 수행되었느냐가 관건 부분은 상수 시간에 수행되므로 𝑂(1) left right 𝑇 𝑛 left right 𝑇 𝑛/2 𝑇 𝑛/4 left = right +𝑂(1) +𝑂(1) 따라서, 시간 복잡도는 𝑇 𝑛 = 𝑇 𝑛 2 + 𝑂 1 !
  • 36. 36 𝑇 𝑛 = 𝑇 𝑛 2 + 𝑂 1 = 𝑇 𝑛 22 + 2𝑂 1 = ⋯ = 𝑇 𝑛 2 𝑘 + 𝑘𝑂(1) 𝑛 = 2 𝑘 , 𝑇 1 = 𝑂(1)라면 ∴ 𝑇 𝑛 = 𝑇 1 + 𝑘𝑂 1 = 𝑘 + 1 𝑂(1) 𝑛 = 2 𝑘 이므로 𝑘 = log2 𝑛 ∴ 𝑇 𝑛 = log2 𝑛 + 1 𝑂 1 = 𝑂 log2 𝑛 = 𝑂(log 𝑛)