Q: Visual C++에서는 std::sort에 무슨 정렬 알고리즘을 써요?
https://stackoverflow.com/questions/22885065/what-sorting-algorithm-does-visual-c-use-in-stdsort
Q:
I've been searching for a while now, but i can't find what algorithm does visual c++ use for the std::sort function, i know the GNU Standard C++ library uses Introsort, but there doesn't seem to be any sources saying which one Microsoft's visual c++ use!
->한참 찾아봤는데 비주얼 c++에서 std::sort에 무슨 알고리즘을 쓰는지 찾질 못하겠네요.
gcc c++에서는 인트로소트를 쓴다는건 아는데 MS 비주얼에서는 뭘 쓰는지 도통 모르겠어요!
A:
If I remember correctly, the implementation uses an algorithm called introsort, a hybrid of quicksort, heapsort, and insertion sort.
->제가 기억하는 바에 의하면, 비주얼의 std::sort도 인트로소트라는 퀵소트와 힙소트의 혼합소트와 삽입소트를 사용하는걸로 압니다.
The basic idea is as follows:
-> 기본개념은 이래요.
Run quicksort, stopping on any subrange whose length is below a preset threshold.
-> 퀵 소트를 쓰다가, 한계를 넘어서 깊이 들어가게 되면 거기서 멈춥니다.
If during the quicksort the recursion depth exceeds a certain limit, stop running quicksort and use heapsort instead.
-> 퀵소트의 재귀 깊이가 한계를 넘으면 퀵소트를 멈추고 대신 힙소트를 쓰는거죠.
At the end, run insertion sort on the whole array.
-> 끝에 가서는 그 배열에서 삽입소트를 씁니다.
Since the elements are all close to their final positions, this will only take time O(n).
-> 삽입소트는 요소들이 전부 최종 위치에 가까울 때부터는 O(n)의 시간만을 소요하기 때문이죠.
The advantage of introsort is that in the common case, it uses quicksort (very fast) until insertion sort is better, getting the advantages of both.
-> 인트로소트의 장점을 꼽자면, 일반적인 상황에서는 삽입소트가 더 좋은 상황일때까지만 퀵소트를 써서, 두가지의 장점을 취하는 점에 있습니다.
In the event that the quicksort starts to degenerate, it uses heapsort, which is O(n log n) worst-case but slightly slower than quicksort on average, to guarantee O(n log n) worst-case runtimes.
->퀵 소트가 나쁜 상황이면 힙소트를 씁니다. 힙소트는 가장 나쁜 경우가 O(n log n)이지만 퀵소트보다는 평균속도가 조금 느리죠. 하지만 최악의 경우도 O(n log n)임을 보장해줍니다.
Overall, it's a very fast, in-place sorting algorithm.
->전체적으로는 되게 빠른 공간-내 정렬이죠.
Hope this helps!
호프는 이것들을 도와줘요!