O(n2) time complexity is not great performance, but the sorting algorithms in this category are easy to understand and useful in some scenarios. These algorithms are space efficient; they only require constant O(1) additional memory space. For small data sets, these sorts compare very favorably against more complex sorts.

In this chapter, you’ll be looking at the following sorting algorithms:

All of these are comparison-based sorting methods. They rely on a comparison method, such as the less-than operator, to order the elements. The number of times this comparison gets called is how you can measure a sorting technique’s general performance.

O (n2) 시간 복잡도는 성능이 좋지 않지만이 범주의 정렬 알고리즘은 이해하기 쉽고 일부 시나리오에서는 유용합니다. 이 알고리즘은 공간 효율적입니다. 상수 O(1) 추가 메모리 공간 만 필요합니다. 작은 데이터 세트의 경우 이러한 정렬은 더 복잡한 정렬과 비교하여 매우 유리합니다.

이 장에서는 다음과 같은 정렬 알고리즘을 살펴 봅니다.

이들 모두 비교 기반 정렬 방법입니다. 요소를 정렬하기 위해보다 작음 연산자와 같은 비교 방법을 사용합니다. 이 비교가 호출되는 횟수는 정렬 기술의 일반적인 성능을 측정하는 방법입니다.

Bubble sort

One of the simplest sorts is the bubble sort, which repeatedly compares adjacent values and swaps them, if needed, to perform the sort. The larger values in the set will therefore "bubble up" to the end of the collection.

가장 간단한 정렬 중 하나는 버블 정렬입니다. 버블 정렬은 인접 값을 반복적으로 비교하고 필요에 따라이를 정렬하여 정렬합니다. 따라서 세트의 값이 클수록 컬렉션이 끝날 때까지 "버블 업"됩니다.