+ 2

Pythnon sort

What is the fastest algorithm sort in python ? time <= O(n)

4th Apr 2020, 7:28 PM
💡Arno Gevorgyan 🐍
💡Arno Gevorgyan 🐍 - avatar
4 odpowiedzi
+ 3
Timsort is Python's built-in sorting mechanism https://en.m.wikipedia.org/wiki/Timsort
4th Apr 2020, 9:00 PM
Tibor Santa
Tibor Santa - avatar
+ 2
who know?
24th Aug 2020, 12:47 PM
💡Arno Gevorgyan 🐍
💡Arno Gevorgyan 🐍 - avatar
+ 1
💡Arno Gevorgyan 🐍 the built in sorting algorithm is recommended to be used, but obviously, you can use other algorithms too. But keep this mind, if you even write a very fast sorting algorithm in python, it won't be that much fast compared to Python's, because its one is written in C. What you can do is, go to cpython's source code and have a look at how the codes are optimized there. Then learn C or Cython, and write your program in the above mentioned language. And then call them using C-Python API. Now moving to algorithms: THERE IS NO SORTING ALGORITHM WHICH CSN RUN IN O(N) OR LESS Decide now what you're going to sacrifice.... 1. Intro Sort #O(nlogn) #faster than Timsort in random datas #sacrifice stability 2. Radix Sort #O(d(n+k)) [d means no of significant digits of the highest no] #almost linear time complexity #sacrifice space 3. Counting Sort #O(n+k) [k means highest no-lowest no] #best if k is small 4. Quad Sort: #O(nlogn) #better than Timsort if n<1000) .........................................
27th Apr 2021, 7:57 PM
Md. Faheem Hossain
Md. Faheem Hossain - avatar
+ 1
...................................... 5. Binary Insertion Sort #O(n^2) #fastest sorting algorithm if n<32 Some others: Shell Sort, Pigeonhole Sort, Flash Sort, Wiki Sort
27th Apr 2021, 8:00 PM
Md. Faheem Hossain
Md. Faheem Hossain - avatar