A simple and efficient implementation of the Counting Sort algorithm in TypeScript. This package provides a stable and linear-time sorting utility that can be used in both Node.js and browser environments.
You can install the package via npm or pnpm:
npm install @omts/counting-sort
This package exports a countingSort
function that sorts an array of non-negative integers using the Counting Sort algorithm. Below is an example of how to use it:
import { countingSort } from '@omts/counting-sort';
// Example usage
const unsortedArray = [3, 6, 8, 10, 1, 2, 1];
const sortedArray = countingSort(unsortedArray);
console.log(sortedArray); // Output: [1, 1, 2, 3, 6, 8, 10]
-
Time Complexity:
-
Best, Average, and Worst Case: O(n + k), where
n
is the number of elements in the input array andk
is the range of the input.
-
Best, Average, and Worst Case: O(n + k), where
-
Space Complexity:
- O(n + k) due to the auxiliary arrays used for counting and output.
-
dev
: Cleans and builds the package in watch mode using Bun. -
build
: Runs a clean build by generating multiple module formats (CJS, ESM, UMD) and type declarations. -
build:esm
: Builds the TypeScript source to ES Module (ESM) format. -
build:cjs
: Builds the TypeScript source to CommonJS (CJS) format. -
build:umd
: Builds the TypeScript source to UMD format with a global nameOmtsCountingSort
. -
build:types
: Generates type declaration files using the TypeScript compiler. -
test
: Runs all test cases using Bun.
Contributions are welcome! If you have any improvements or suggestions, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.