본문 바로가기
프로그램

알고리즘 시간복잡도 그래프 및 빠른 순서

by 오디세이99 2023. 5. 12.
728x90
반응형
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 100)

fig, axs = plt.subplots(2, 3)
plt.rcParams['font.family'] = 'NanumGothic'  # 한글 가능하도록 폰트 설정
fig.suptitle("시간 복잡도에서 빠른 순서:O(1) < O(log n) < O(n) < O(n log n) < O(n^2) < O(n^3) < O(2^n) < O(n!)")

axs[0, 0].plot(x, np.ones(99))
axs[0, 0].set_title('O(1)')
axs[0, 1].plot(x, np.log2(x))
axs[0, 1].set_title('O(log n)')
axs[0, 2].plot(x, x)
axs[0, 2].set_title('O(n)')
axs[1, 0].plot(x, x * np.log2(x))
axs[1, 0].set_title('O(n log n)')
axs[1, 1].plot(x, x ** 2)
axs[1, 1].set_title('O(n^2)')
axs[1, 2].plot(x, 2 ** x)
axs[1, 2].set_title('O(2^n)')

for ax in axs.flat:
    ax.set(xlabel='Input Size', ylabel='Time Complexity')

for ax in axs.flat:
    ax.label_outer()
    
plt.show()

728x90
반응형

댓글