Skip to main content

Quick Sort

A recursive sorting algorithm which makes use of Divide and Conquer. The function will call itself on both halves, followed by a merge function to merge the 2 sorted halves.
Best Time Complexity: O(nlogn)
Worse Time Complexity: O(n2)

Usage

quick_sort(lst:list, key:Callable = lambda x:x, visualise:bool = False, animate:bool = False)

Parameters:
      lst : List
            A list of elements to be sorted
      key : Callable
            A custom function on how the elements should be sorted
      visualise : Boolean
            If true, the generator object will record the state of the list after each iteration
      animate : Boolean
            If true, the generator object will record each change in the state of the list

Returns:
      List
            A list of state changes that happened to the list

Comments

  1. This function does not print or perform animations. Find out how to do that here.

Example

from jellybeans.algos import quick_sortlst = [9, 19, 1, 17, 6, 20, 4, 13, 15, 3]quick_sort(lst)print(lst) # [1, 3, 4, 6, 9, 13, 15, 17, 19, 20]