[c++] STL 알고리즘의 시간 복잡도
C++ 표준 라이브러리(STL)는 다양한 유용한 알고리즘들을 제공합니다. 이러한 알고리즘은 일반적으로 최적화되어 있어서 성능이 우수합니다. 그러나 각 알고리즘의 시간 복잡도는 해당 알고리즘의 작동 방식에 따라 달라집니다. 여기서는 몇 가지 자주 사용되는 C++ STL 알고리즘의 시간 복잡도에 대해 알아보겠습니다.
이진 탐색 알고리즘 (Binary Search Algorithm)
std::binary_search
: O(log n)
정렬 알고리즘 (Sorting Algorithms)
std::sort
: O(n log n)std::partial_sort
: O(n log k) (n은 원본 범위 크기, k는 부분 정렬된 범위 크기)std::nth_element
: O(n)
검색 알고리즘 (Search Algorithms)
std::find
: O(n)std::find_if
: O(n)std::count
: O(n)std::count_if
: O(n)std::lower_bound
: O(log n)std::upper_bound
: O(log n)
병합 알고리즘 (Merge Algorithms)
std::merge
: O(n)
힙 알고리즘 (Heap Algorithms)
std::make_heap
: O(n)std::push_heap
: O(log n)std::pop_heap
: O(log n)std::sort_heap
: O(n log n)
STL 알고리즘의 시간 복잡도를 고려하여 알고리즘을 선택하는 것은 프로그램의 성능을 향상시키는 데 도움이 될 수 있습니다.
더 자세한 정보는 cppreference를 참고하세요.