quicksort

quicksort in python always return a unsorted array

quicksort in python always return a unsorted array Question: i defined a quicksort in python.It printed a sorted list, but the return list is unsorted. [1, 5, 7, 8] #this is result of print(array) in quicksort [7, 5, 8, 1] #this is result of testing it’s so weired def quickSort(array): if len(array) <= 1: return …

Total answers: 3

How to build a sorting algorithm with 2 keys in Python?

How to build a sorting algorithm with 2 keys in Python? Question: I’m aware that Python has a very nice function sorted() for this but I’d like to implement my own function to understand the logic. I have a list of strings and I’d like to sort them first by length, then alphabetically. For example, …

Total answers: 3

Quicksort in-place for list of lists

Quicksort in-place for list of lists Question: I got a task to sort data with quicksort in-place. The input is a list of lists (name, score1, score2). The data should be sorted by score1 in descending order, then (if equal) by score2 in ascending order, then (if equal) by name in ascending order. Example input: …

Total answers: 1

Python: Quicksort with median of three

Python: Quicksort with median of three Question: I’m trying to change this quicksort code to work with a pivot that takes a “median of three” instead. def quickSort(L, ascending = True): quicksorthelp(L, 0, len(L), ascending) def quicksorthelp(L, low, high, ascending = True): result = 0 if low < high: pivot_location, result = Partition(L, low, high, …

Total answers: 3

Quicksort with Python

Quicksort with Python Question: I am totally new to python and I am trying to implement quicksort in it. Could someone please help me complete my code? I do not know how to concatenate the three arrays and print them. def sort(array=[12,4,5,6,7,3,1,15]): less = [] equal = [] greater = [] if len(array) > 1: …

Total answers: 36

Python faster than compiled Haskell?

Python faster than compiled Haskell? Question: I have a simple script written in both Python and Haskell. It reads a file with 1,000,000 newline separated integers, parses that file into a list of integers, quick sorts it and then writes it to a different file sorted. This file has the same format as the unsorted …

Total answers: 7