Module dsa.sorttools
Module to access functions for sort benchmarking.
Functions
def array_details(array: list) ‑> str
-
Return a string with details about the array.
Args
array
- the array to analyze.
Returns
A string with the count of elements, first 10 elements, and last 10 elements.
def filled_array(n: int) ‑> list
-
Return an array filled with integers from 0 to n-1.
Args
n
:int
- the number of integers to generate.
Returns
Array filled with integers from 0 to n-1.
def generate_almost_sorted_array(size: int, swaps: int) ‑> list
-
Generate an almost sorted array of a given size with a specified number of swaps.
Args
size
:int
- The size of the array to generate.
swaps
:int
- The number of adjacent elements to swap to create disorder.
Returns
list
- An array of integers that is mostly sorted with a few local swaps.
def is_sorted(array: list) ‑> bool
-
Return a boolean on whether an array is sorted in ascending order or not.
Args
array
- the array to verify.
Returns
True if the array is sorted, False otherwise.
def rand_int_array(n: int, maxnum: int) ‑> list
-
Return an array of n integers of random numbers from 0 to maxnum.
Args
n
:int
- The number of integers to generate.
maxnum
:int
- The maximum number in a range (0-maxnum inclusive).
Returns
Array of n integers of random numbers from 0 to maxnum.
def shuffle_array(n: int) ‑> list
-
Return a shuffled array filled with integers from 0 to n-1.
Args
n
:int
- The number of integers to generate.
Returns
Array shuffled with integers from 0 to n-1.