A comprehensive TypeScript library providing efficient implementations of common Data Structures and Algorithms.
- 🚀 Efficient implementations of classic algorithms
- 📦 Written in TypeScript with full type support
- ✅ Thoroughly tested with Vitest
- 📚 Well-documented API
- 🎯 Zero dependencies
# Using bun
bun add dsa-kit
# Using npm
npm install dsa-kit
# Using pnpm
pnpm add dsa-kit
# Using yarn
yarn add dsa-kit
This project is developed using Bun, a fast all-in-one JavaScript runtime and toolkit.
# Install bun (if you haven't already)
curl -fsSL https://bun.sh/install | bash
# Clone the repository
git clone https://github.com/yourusername/dsa-kit
# Install dependencies
bun install
# Run tests
bun test
# Run tests in watch mode
bun test --watch
# Type checking
bun run typecheck
# Run tests with coverage
bun test --coverage
# Build the package
bun run build
import { mergeSort } from 'dsa-kit';
// Ascending order (default)
const ascArray = mergeSort([5, 2, 8, 1, 9]);
console.log(ascArray); // [1, 2, 5, 8, 9]
// Descending order
const descArray = mergeSort([5, 2, 8, 1, 9], 'desc');
console.log(descArray); // [9, 8, 5, 2, 1]
import { DFSTraversal, TreeNode } from 'dsa-kit';
const tree = {
value: 1,
left: { value: 2, left: null, right: null },
right: { value: 3, left: null, right: null }
};
const dfs = new DFSTraversal();
// Different traversal methods
const inorderResult = dfs.inOrder(tree); // [2, 1, 3]
const preorderResult = dfs.preOrder(tree); // [1, 2, 3]
const postorderResult = dfs.postOrder(tree); // [2, 3, 1]
import { BFSTraversal, TreeNode } from 'dsa-kit';
const bfs = new BFSTraversal();
// Flat level-order traversal
const flatResult = bfs.levelOrder(tree);
console.log(flatResult); // [1, 2, 3]
// Level-wise traversal
const levelWiseResult = bfs.levelOrder(tree, true);
console.log(levelWiseResult); // [[1], [2, 3]]
arr
: Array of numbers to sortorder
: Optional sorting order ('asc' or 'desc')- Returns: Sorted array
- Time Complexity: O(n log n)
- Space Complexity: O(n)
inOrder(root: TreeNode | null): number[]
preOrder(root: TreeNode | null): number[]
postOrder(root: TreeNode | null): number[]
levelOrder(root: TreeNode | null, byLevel?: boolean): number[] | number[][]
byLevel
: If true, returns array of arrays where each sub-array represents a tree level
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please:
- Check the GitHub Issues
- Review the documentation
- Submit a new issue if needed
If you found this package helpful, please give it a ⭐️ on GitHub!
MIT License - see the LICENSE file for details.