O(1)
def print_item(something_list, item_num):
print(something_list[item_num])
O(n)
n에 따라 n번, 2n번, 4n+2 번 등등 실행 → 모두 O(n) 으로 표기
def print_double_forloop(n):
for i in range(n):
print(i)
for j in range(n):
print(j)
O()
n에 따라 번, 번 등등 실행 → 모두 O() 으로 표기
def print_double_forloop(n):
for i in range(n):
for j in range(n):
print(i * j)
O()
n의 탐색범위가 진행될때마다 절반씩 줄어든다 → O() [트리 사용시 관찰]
def binsearch(x_list, target):
min_point, max_point = 0, len(x_list)
while True:
if a == b:
return -1
center = (a + b) // 2
if x_list[center] == target:
return center
if x_list[c] > target: # 구간을 왼쪽 절반으로 줄임
min_point, max_point = min_point, center
else: # 구간을 오른쪽 절반으로 줄임
min_point, max_point = center + 1, max_point
def print_powers_of_two(n):
i = 1
while i < n:
print(i)
i = i * 2
O(
O() 과 반대로 n이 늘어날 때마다 약 두배씩 늘어난다. → O(
function func (num){
if(num <= 1){
return num;
}else{
return func(num-1) + func(num-2);
}
}