Hello guys, what is the fastest way to sort an Int...
# announcements
g
Hello guys, what is the fastest way to sort an Int[] ?
d
Just call
sort
😛
g
I am aware about the sort() in kotlin. is that good enough to take care of the performance @evanchooly
d
Yes.
You can usually trust the JDK to know what they are doing 🙂
g
Cool, thanks for that link to the doc
e
“do the simplest thing that can possibly work.” then optimize as necessary.
💯 2
👍 1
s
you can always just
ctrl/cmd+b
into the definition of the method in question…
many of the standard extensions provided on collection types are backed by stuff in the java stdlib anyhow
and the docs will be right there
j
if its a known range ie, 1-100 you can do in o(n) time at cost of memory
but otherwise quicksort in nlogn
g
you mean the dataset @Jeremy Rempel?
or the size
j
the values, say all values in int[] were between 0-100
and you had a million of them
g
Okay, sp it i had a larger range of values say -1000 to 1000
quicksort it is ?
j
no, 0-100 is just a number. its just a defined range
g
That's what i meant
j
you'd loop through your array once and use a map to store map[i] = cnt
in O(n) time
then map[i] will represent the number of elements at i
then second loop from 0..range and copy values into a new array
O(n) time
you are creating a map of size n so its a tradeoff between time and memory