"""
Design sketch for QuickSort Algorithm.
"""
import sys
# Quicksort might cause a recursion depth >5000 -> increase limit
sys.setrecursionlimit(6000)
def quicksort(array, if_randomized=True):
"""
Sort array in ascending order.
Wrapper for the sorting method.
Args:
int[] array: integer array
bool if_randomized: method how to pick pivot. True if randomized.
"""
def quicksort_recursive(array, left, right, if_randomized):
"""
Method that recursively divides array on parts and calls the
rearrangement procedure on each part.
Args:
int[] array: integer array that has to be sorted
int left: left index from which the rearrangement starts.
int right: right index till which the rearrangement goes.
bool if_randomized: method how to pick pivot. True if randomized.
"""
def quicksort_divide(array, left, right, if_randomized):
"""
Method that executes the divide step of the algorithm. Method chooses
pivot element and performs rearrangement of the elements inside of
the array in such a way, that elements that are smaller than pivot are
placed to the left of it, and elements that are larger than pivot are
placed the the right of pivot.
Args:
int[] array: integer array that has to be rearranged.
int left: left index from which the rearrangement starts.
int right: right index till which the rearrangement goes.
bool if_randomized: method how to pick pivot. True if randomized.
Returns:
int: index where the pivot after the split is.
"""