정확한 분석을 수행하려면 알고리즘의 구조를 보기 위한 소스 코드를 조사해야 한다. 다음 예
제 코드에서 핵심 연산
ct
=
ct
+
1
을 몇 번 수행했는지 살펴보자.
for i in range(100):
for j in range(N):
ct = ct + 1
외부
i
루프에서
100
회 수행하는데 각 루프에서 내부
j
루프가
N
회 수행된다. 따라서
ct
=
ct
+
1
은 총
100
×
N
회 수행된다. 크기가
N
인 문제 인스턴스에서 앞선 코드를 실행하기 위
한 총 시간
T
(
N
)은 적절히 선택된
c
의
c
×
N
보다 작다. 실제 컴퓨터에서 해당 코드를 실행하
면 정확한
c
를 결정할 수 있을 것이다. 더 정확히는 빅오 표기법을 사용해 해당 코드의 성능을
O
(
N
)으로 나타낼 수 있다.
각기 다른 컴퓨팅 시스템에서 이 코드를 수천 번 수행해 매번 다른
c
를 계산할 수 있다. 이 사
실은 참이며
O
(
N
)으로 코드 성능을 분류할 수 있는 이유다. 이론적 세부 사항은 설명하지 않
지만, 알고리즘의 연산 횟수를 나타내는 함수
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.