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