Skip to Content
똑똑한 코드 작성을 위한 실전 알고리즘
book

똑똑한 코드 작성을 위한 실전 알고리즘

by 조지 하이네만, 윤대석
May 2022
Beginner to intermediate
296 pages
5h 54m
Korean
Hanbit Media, Inc.
Content preview from 똑똑한 코드 작성을 위한 실전 알고리즘
154
똑똑한 코드 작성을 위한 실전 알고리즘
그림
5-3
삼각수 공식 시각화:
1
부터
7
까지의 합은
28
이다.
5.3
성능이
O
(
N
2
)인 정렬 알고리즘의 구조
선택 정렬을 분석해보면 비교 횟수의 최고차항이
N
2
이며, 이는 성능이
O
(
N
2
)이라는 의미다.
N
개 값을 정렬할 때
N
-
1
회의 개별 단계가 어떻게 수행되는지 살펴보며 그 이유를 알아보자.
첫 단계에서
N
-
1
회 비교를 통해 가장 작은 값을 찾고 단 하나의 값만 알맞은 위치로 이동한다.
이후
N
-
2
개의 단계 각각은 마지막 단계에서 더 이상 작업이 없을 때까지 하나씩 (아주 천천
히) 감소한다. 비교 횟수를 줄일 수 있을까?
삽입 정렬
Insertion
Sort
은 선택 정렬 (마찬가지로
N
-
1
개의 개별 단계를 사용해 배열을 왼쪽에서 오
른쪽으로 정렬)과는 다른 알고리즘이다.
A
[
0
]
가 알맞은 위치에 있다고 가정하고 시작한다(배
열에서 가장 작은 값일 수 있다 ). 삽입 정렬의 첫 번째 단계에서
A
[
1
]
A
[
0
]
보다 작은 값이면
오름차순 정렬이 필요하므로 두 값을 교환한다. 두 번째 단계에서는
A
[
2
]
의 값을 처음
3
개 값
만 고려해 알맞은 위치로 삽입하려고 시도한다. 여기에는 세 가지 가능성이 존재한다.
A
[
2
]
알맞은 위치이거나,
A
[
0
]
A
[
1
]
사이에 삽입해야 하거나,
A
[
0
]
앞에 삽입해야 ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’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
QuotationMarkI 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
QuotationMarkI’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
QuotationMarkI'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.
Mark W.
Embedded Software Engineer

You might also like

데이터 익명화를 위한 파이프라인

데이터 익명화를 위한 파이프라인

루크 아버클, 칼리드 엘 에맘
개발 7년차, 매니저 1일차

개발 7년차, 매니저 1일차

권원상, 한민주, 카미유 푸르니에

Publisher Resources

ISBN: 9791162245644