
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
github.com/kdgyun/gosortingalgorithms
ํ๊ธ ๋ฌธ์ | English Document
Go ์ธ์ด๋ก ์์ฑ๋ ๋ค์ํ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ๋ค์ด ์์ต๋๋ค :octocat:
Go ์ธ์ด๊ฐ ์ค์น ๋์ด ์๋ค๋ฉด, go get ๋ช ๋ น์ด๋ฅผ ์คํํ์ฌ GoSoringAlgorithms ํจํค์ง๋ฅผ ๋ฐ์์ต๋๋ค.
$ go get github.com/kdgyun/GoSortingAlgorithms
๊ฐ๋จํฉ๋๋ค!
package main
import (
"github.com/kdgyun/GoSortingAlgorithms/sorts"
crand "crypto/rand"
"fmt"
"math"
"math/big"
"math/rand"
"sort"
)
// ๋๋ค ์ ์ ์ฌ๋ผ์ด์ค ์์ฑ๊ธฐ
func SliceBuilder(len int) []int {
seed, _ := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
rand.Seed(seed.Int64())
var slice []int
for i := 0; i < len; i++ {
slice = append(slice, rand.Int())
}
return slice
}
func main() {
slice := SliceBuilder(1000000)
sorts.QuickSort(slice) // sorts.____(slice []int)
isSorted := sort.SliceIsSorted(slice, func(i, j int) bool {
return slice[i] < slice[j]
})
fmt.Print(isSorted)
}
symplytest ๋ฅผ ํตํด ์ฝ๊ฒ ํ ์คํธ ํ ์ ์์ต๋๋ค.
package main
import (
"github.com/kdgyun/GoSortingAlgorithms/simplytest"
)
func main() {
simplytest.RunTest()
}
์ถ๋ ฅ ์์
+==================================================================================+
| Random Test |
+==================================================================================+
...
[array length : 100000]
make arrays...
running bubble sort...
running cocktail sort...
...
running intro sort...
running parallel intro sort...
running cycle sort...
+-------------------------------------------------------------------------------------------------+
| name | ns | ms | verify | (err mag)
|-------------------------------------------------------------------------------------------------|
| bubble sort | 13016202738 ns | 13016 ms | true |
|-------------------------------------------------------------------------------------------------|
| cocktail sort | 8922656474 ns | 8922 ms | true |
|-------------------------------------------------------------------------------------------------|
| tim sort | 11419013 ns | 11 ms | true |
|-------------------------------------------------------------------------------------------------|
| bitonic sort | 32333072 ns | 32 ms | true |
|-------------------------------------------------------------------------------------------------|
...
|-------------------------------------------------------------------------------------------------|
| intro sort | 6665792 ns | 6 ms | true |
|-------------------------------------------------------------------------------------------------|
| parallel intro sort | 2537508 ns | 2 ms | true |
|-------------------------------------------------------------------------------------------------|
| cycle sort | 20209957747 ns | 20209 ms | true |
+-------------------------------------------------------------------------------------------------+
option.go
๋ฅผ ํตํด ์ฌ์ฉ์๊ฐ ์ฝ๊ฒ ํ
์คํธ ํ์์ ์กฐ์ ํ ์ ์์ผ๋ฉฐ, 3๊ฐ์ง ์ฃผ์ ์ต์
์ ์ ๊ณตํฉ๋๋ค.
์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ ์ ํ ํน์ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ๋ง ํ ์คํธ ํน์ ์ ์ธํ๊ณ ์ ํ๋ค๋ฉด ํ ์คํธํ๊ณ ์ ํ๋ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ ์ด๋ฆ์ ์ฐพ์ ๋ณ์๋ฅผ true ๋๋ false๋ก ๋ณ๊ฒฝํฉ๋๋ค. (True : ํ ์คํธ ํ์ฉ, false : ํ ์คํธ ๋นํ์ฉ)
ex) SHELL_SORT Activate = true
ํ ์คํธ ํ ์ฌ๋ผ์ด์ค์ ๊ธธ์ด ๋ณ๊ฒฝ. ํ ์คํธํ ์ฌ๋ผ์ด์ค์ ๊ธธ์ด๋ฅผ ๋ณ๊ฒฝํ๋ ค๋ฉด 'lengths' ๋ณ์์ ์ฌ๋ผ์ด์ค๋ฅผ ์ํ๋ ๊ฐ์ผ๋ก ์ค์ ํ ์ ์์ต๋๋ค. ์๋ ์์๋ ๊ธธ์ด 35, 50,000, 100,000 ์ฌ๋ผ์ด์ค์ ๋ํด ๊ฐ๊ฐ ํ ์คํธ ํ๊ฒ ๋ฉ๋๋ค.
ex) var lengths = [...]int{35, 50000, 100000}
์ฌ๋ผ์ด์ค ์ ํ ๋ณ๊ฒฝ.
๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฆ์ฐจ์, ๋ด๋ฆผ์ฐจ์ ๋ฐ ๋๋ค ๋ฐ์ดํฐ๋ก ๊ตฌ์ฑ๋ ๊ฐ๊ฐ์ ๋ชจ๋ ์ฌ๋ผ์ด์ค๊ฐ ํ
์คํธ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ ํน์ ๋ฐ์ดํฐ ์ ํ์ ๋นํ์ฑํํ๋ ค๋ฉด ๋ณ์๋ฅผ false๋ก ๋ณ๊ฒฝํ๋ฉด ๋ฉ๋๋ค.
ex) ASCENDING_TEST Activate = false
Go ์ธ์ด๋ ๋ฐฐ์ด๊ณผ ์ฌ๋ผ์ด์ค๊ฐ ๊ตฌ๋ถ๋์ด ์์ต๋๋ค. ํ์ง๋ง, ์ผ๋ฐ์ ์ผ๋ก ๊ธฐํ ์ธ์ด์์๋ ๋ฐฐ์ด์ด ์ต์ํ๊ธฐ ๋๋ฌธ์ ํด๋น ์๊ณ ๋ฆฌ์ฆ์ ์ค๋ช ํ ๋์๋ ๋ฐฐ์ด๋ก ํต์ผํ์ฌ ์ค๋ช ํฉ๋๋ค.
ํ์ฌ ์ ๋ฐ์ดํธ ๋ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ:
name | function name |
---|---|
Bubble Sort | BubbleSort |
Cocktail Sort | CocktailSort |
Insertion Sort | InsertionSort |
Selection Sort | SelectionSort |
Shell Sort | ShellSort |
Merge Sort (bottom-up) | BottomUpMergeSort |
Merge Sort (top-down) | TopDownMergeSort |
Merge Sort (parallel) | ParallelMergeSort |
Heap Sort | HeapSort |
Quick Sort (left-pivot) | QuickSortLP |
Quick Sort (middle-pivot) | QuickSort |
Quick Sort (left-pivot) | QuickSortRP |
Quick Sort (left-pivot with parallel) | ParallelQuickSortLP |
Quick Sort (middle-pivot with parallel) | ParallelQuickSort |
Quick Sort (left-pivot with parallel) | ParallelQuickSortRP |
Dual-pivot Quick Sort | DualPivotQuickSort |
Dual-pivot Quick Sort (parallel) | ParallelDualPivotQuickSort |
Binaray Insertion Sort | BinarySort |
Tim Sort | TimSort |
Bitonic Sort | BitonicSort |
Bitonic Sort (parallel) | ParallelBitonicSort |
Intro Sort | IntroSort |
Intro Sort (parallel) | ParallelIntroSort |
Cycle Sort | CycleSort |
Odd-Even Sort | OddEvenSort |
Odd-Even Merge Sort | OddEvenMergeSort |
Odd-Even Merge Sort (parallel) | ParallelOddEvenMergeSort |
Comb Sort | CombSort |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | Yes | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | Yes | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | Yes | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
*์ ์ฉ ๋ Gap ์ํ์ค๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. Ciura sequence
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
depends on gap sequence | Yes | No | total : |
๋ณํฉ ์ ๋ ฌ์ ๋ถํ ์ ๋ณต ์๊ณ ๋ฆฌ์ฆ์ ๊ธฐ๋ฐ์ผ๋ก ํฉ๋๋ค.
๊ฐ๋ ์ ์ผ๋ก ๋ณํฉ ์ ๋ ฌ์ ๋ค์๊ณผ ๊ฐ์ด ์๋ํฉ๋๋ค:
3๊ฐ์ง ์ ํ์ ๋ณํฉ ์ ๋ ฌ์ ์ง์ํฉ๋๋ค.
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
No | Yes | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
3๊ฐ์ง ์ ํ์ ํต ์ ๋ ฌ์ ์ง์ํฉ๋๋ค.
๋ํ ๊ฐ ์๊ณ ๋ฆฌ์ฆ์ ์ฌ๊ท ํธ์ถ์ ๋ณ๋ ฌํ๋ ์ง์ํฉ๋๋ค.
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
2๊ฐ์ง ์ ํ์ ์ด์ค ํผ๋ฒ ํต ์ ๋ ฌ์ ์ง์ํฉ๋๋ค.
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | yes | total : |
Timsort๋ ๋ค์ํ ์ข
๋ฅ์ ์ค์ ๋ฐ์ดํฐ์์ ์ ์ํ๋๋๋ก ์ค๊ณ๋ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก, ๋ณํฉ ์ ๋ ฌ๊ณผ ์ฝ์
์ ๋ ฌ(๋๋ ์ด์ง ์ฝ์
์ ๋ ฌ)์์ ํ์๋์ด ํผํฉ ๋ ์์ ์ ์ธ ํ์ด๋ธ๋ฆฌ๋ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ ์
๋๋ค. Python ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์์ ์ฌ์ฉํ๊ธฐ ์ํด 2002๋
Tim Peters์ ์ํด ๊ตฌํ๋์์ต๋๋ค.
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | yes | total : |
2๊ฐ์ง ์ ํ์ ์๊ณ ๋ฆฌ์ฆ์ ์ง์ํฉ๋๋ค.
Type | Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|---|
non-parallel | Yes | No | total : | |||
parallel | Yes | No | total : |
์ธํธ๋ก ์ ๋ ฌ์ ์ต์
์ ๊ฒฝ์ฐ์๋ ํ๊ท ์ ์ผ๋ก ๋น ๋ฅธ ์ฑ๋ฅ๊ณผ ๋ฐ (์ ๊ทผ์ ์ผ๋ก) ์ต์ ํ ๋ ํ์ด๋ธ๋ฆฌ๋ ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ์
๋๋ค. ํต์ ๋ ฌ๋ก ์์ํ์ฌ ์ฌ๊ท ๊น์ด๊ฐ ์ ๋ ฌ๋๋ ๋ฐฐ์ด์ ์์ ๊ฐ์์ ๋ฐ๋ฅธ ๊น์ด ์๊ณ๊ฐ(maximum depth: ) ์์ค์ ์ด๊ณผํ๋ฉด ํ ์ ๋ ฌ๋ก ์ ํํ๊ณ ๋ถํ ๋ ๋ฐฐ์ด์ ์์ ๊ฐ์๊ฐ ๊ธธ์ด ์๊ณ๊ฐ(16) ๋ฏธ๋ง์ด๋ฉด ์ฝ์
์ ๋ ฌ๋ก ์ ํํฉ๋๋ค.
2๊ฐ์ง ์ ํ์ ์๊ณ ๋ฆฌ์ฆ์ ์ง์ํฉ๋๋ค.
non-parallel
์ ๋ ฌํ ๋ฐฐ์ด์์ ํต ์ ๋ ฌ์ ์ฌ์ฉํ ๋ ์์(ํผ๋ฒ)๋ฅผ ์ ํํ๊ณ ์ ํ ๋ ํผ๋ฒ์ ์ ์ธํ ๋ค๋ฅธ ์์๋ค์ด ํผ๋ฒ๋ณด๋ค ์๊ฑฐ๋ ํฐ์ง ์ฌ๋ถ์ ๋ฐ๋ผ ๋ ๊ฐ์ ํ์ ๋ฐฐ์ด๋ก ๋ถํ ํ๊ณ ์ฌ๊ท ๊น์ด๊ฐ ํน์ ์๊ณ๊ฐ(maximum depth: )์ ๋๊ธฐ ์ ๊น์ง ์ด๋ฌํ ๊ณผ์ ์ ์ฌ๊ท์ ์ผ๋ก ๊ฑฐ์นฉ๋๋ค.
parallel
์ฌ๊ท ํธ์ถ์ ๋ณ๋ ฌํ๋ฅผ ํตํด ๊ฐ ๋ณ๋ ฌํ ๋ ์ด์ค ํผ๋ฒ ํต ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ์ ๋ถํ ๋ ๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ ์๊ณ๊ฐ๋ณด๋ค ์์์ง๊ธฐ ์ ๊น์ง ๋ฐฐ์ด์ ์ฌ๊ท์ ์ผ๋ก ๋ถํ ํ์ฌ ์ ๋ ฌํฉ๋๋ค.
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | Yes | total : |
ํ์ง ๋ณํฉ ์ ๋ ฌ์ ์ฌ์ด์ฆ๋
, ๊น์ด๋
๋ฅผ ๊ฐ๋ ๋คํธ์ํฌ ์ ๋ ฌ์ ์ํด Ken Batcher ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ ์
๋๋ค.
Type | Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|---|
non-parallel | Yes | yes | total : | |||
parallel | Yes | yes | total : |
Worst-Case | Average-Case | Best-Case | in-place | stable | Space Complexity |
---|---|---|---|---|---|
Yes | No | total : |
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.