Skip to content

About

This aims at showcasing popular sorting algorithms with the kotlin programming language.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Algorithms with Kotlin

Popular sorting and searching algorithms implemented in Kotlin. Most of them are written as generic extension functions (for example fun <E: Comparable<E>> Array<E>.quickSort()), so they sort numbers, strings, or anything else that is comparable. Each file has its own main() with a small demo that prints its result.

Algorithms

File Algorithm Average time
Bubble sort.kt Bubble sort O(n²)
Selection sort.kt Selection sort O(n²)
Insertion sort.kt Insertion sort O(n²)
Merge sort.kt Merge sort O(n log n)
Quick sort.kt Quick sort (Lomuto partition) O(n log n)
Heap sort.kt Heap sort O(n log n)
Linear search.kt Linear search O(n)
Binary search.kt Binary search on a sorted array O(log n)

Run it

git clone https://github.com/NinjaShadowBoy/AlgorithmsWithKotlin.git
cd AlgorithmsWithKotlin

In IntelliJ IDEA: open the folder, then click the run icon next to the main() of the file you want to try.

From the command line, with the Kotlin compiler installed, compile and run one file at a time:

kotlinc "Quick sort.kt" -include-runtime -d quicksort.jar
java -jar quicksort.jar

Example output:

Ascending Order
[2, 12, 12, 23, 43, 76, 89]
[C, C++, Java, Kotlin, Matlab, Python, R]

The out/ folder is IntelliJ's compiled output and can be ignored.

About

This aims at showcasing popular sorting algorithms with the kotlin programming language.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages