-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path복잡도
More file actions
42 lines (31 loc) · 944 Bytes
/
복잡도
File metadata and controls
42 lines (31 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
시간 복잡도 : 알고리즘 실행에 필요한 연산의 "횟수"
공간 복잡도 : 알고리즘 실행에 필요한 "메모리의 양"
<<시간 측정>>
import time
start_time = time.time();
...
...
end_time = time.time();
print(end_time - start_time);
<< 리스트 컴프리헨션>>
* 대괄호 안에 조건문과 반복문을 넣는 방식으로 리스트를 초기화*
ex) array = [i for i in range(20) if i % 2 == 1]
print(array)
-> [1,3,5,7,9,11,13,15,17,19]
원래 코드로 작성하면
array = [];
for i in range(20):
if i % 2 == 1:
array.append(i);
print(array);
-> 훨씬 복잡하다
ex) 이차원 리스트 초기화
n = 3;
m = 4;
array = [[0] * m for _ in range(n)]
print(array)
(_)언더바 -> 반복을 위한 변수의 값을 무시할때 언더바를 사용한다.
<<집합 자료형>>
data = { , , ,} -> 콤마로 구분 // 딕셔너리와 차이점
*중복을 허용하지 않음
*순서가 없음