mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-01 10:45:21 +08:00
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// File: time_complexity_test.go
|
|
// Created Time: 2022-12-13
|
|
// Author: msk397 ([email protected])
|
|
|
|
package chapter_computational_complexity
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestTimeComplexity(t *testing.T) {
|
|
n := 8
|
|
fmt.Println("입력 데이터 크기 n =", n)
|
|
|
|
count := constant(n)
|
|
fmt.Println("상수 차수의 연산 횟수 =", count)
|
|
|
|
count = linear(n)
|
|
fmt.Println("선형 차수의 연산 횟수 =", count)
|
|
count = arrayTraversal(make([]int, n))
|
|
fmt.Println("선형 차수(배열 순회)의 연산 횟수 =", count)
|
|
|
|
count = quadratic(n)
|
|
fmt.Println("제곱 차수의 연산 횟수 =", count)
|
|
nums := make([]int, n)
|
|
for i := 0; i < n; i++ {
|
|
nums[i] = n - i
|
|
}
|
|
count = bubbleSort(nums)
|
|
fmt.Println("제곱 차수(버블 정렬)의 연산 횟수 =", count)
|
|
|
|
count = exponential(n)
|
|
fmt.Println("지수 차수(반복문 구현)의 연산 횟수 =", count)
|
|
count = expRecur(n)
|
|
fmt.Println("지수 차수(재귀 구현)의 연산 횟수 =", count)
|
|
|
|
count = logarithmic(n)
|
|
fmt.Println("로그 차수(반복문 구현)의 연산 횟수 =", count)
|
|
count = logRecur(n)
|
|
fmt.Println("로그 차수(재귀 구현)의 연산 횟수 =", count)
|
|
|
|
count = linearLogRecur(n)
|
|
fmt.Println("선형 로그 차수(재귀 구현)의 연산 횟수 =", count)
|
|
|
|
count = factorialRecur(n)
|
|
fmt.Println("팩토리얼 차수(재귀 구현)의 연산 횟수 =", count)
|
|
}
|