Skip to content

msboffl/ds-algo

Repository files navigation

Data Structures and Algorithms Library

A comprehensive TypeScript library implementing fundamental data structures and algorithms, inspired by Java's Collections Framework. Built with modern TypeScript practices and comprehensive testing.

πŸ“¦ Packages

This monorepo contains the following packages:

  • @ds-algo/collections - Collection framework with interfaces and implementations

    • Core interfaces (Collection, Iterable, Iterator)
    • Abstract base classes (planned)
    • Concrete implementations (planned)
    • Collection-specific algorithms (planned)
  • @ds-algo/algorithms - Algorithm implementations

    • Sorting algorithms (Quick Sort, Merge Sort, Bubble Sort, Heap Sort)
    • Searching algorithms (Binary Search, Linear Search, Depth First Search)
    • Graph algorithms (Dijkstra, BFS, DFS, Topological Sort)
    • Dynamic programming solutions (Fibonacci, LCS, Knapsack)
    • String algorithms (KMP, Boyer-Moore, Rabin-Karp) - planned
    • Mathematical algorithms (GCD, LCM, Prime factorization) - planned

πŸ—οΈ Project Structure

packages/ β”œβ”€β”€ collections/ # Collection framework β”‚ β”œβ”€β”€ src/ β”‚ β”‚ β”œβ”€β”€ interfaces/ # Core interfaces (Collection, Iterable, Iterator) β”‚ β”‚ β”œβ”€β”€ abstracts/ # Abstract base classes (planned) β”‚ β”‚ β”œβ”€β”€ classes/ # Concrete implementations (planned) β”‚ β”‚ └── algorithms/ # Collection-specific algorithms (planned) β”‚ β”œβ”€β”€ tests/ # Test files β”‚ └── README.md # Package documentation └── algorithms/ # Algorithm implementations β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ sorting/ # Sorting algorithms (planned) β”‚ β”œβ”€β”€ searching/ # Searching algorithms (planned) β”‚ β”œβ”€β”€ graph/ # Graph algorithms (planned) β”‚ β”œβ”€β”€ dynamic-programming/ # DP solutions (planned) β”‚ β”œβ”€β”€ utils/ # Utility functions (planned) β”‚ └── index.ts # Main exports β”œβ”€β”€ tests/ # Test files └── README.md # Package documentation 

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 8+

Installation

# Clone the repository git clone https://github.com/your-username/ds-algo.git cd ds-algo # Install dependencies pnpm install # Build all packages pnpm run build # Run tests pnpm run test

Usage

Collections Package

import { Collection, Iterable, Iterator } from '@ds-algo/collections'; // Define a custom collection class MyCollection<T> implements Collection<T> { private items: T[] = []; iterator(): Iterator<T> { return new MyIterator(this.items); } } // Use the collection interfaces const collection: Collection<number> = new MyCollection<number>();

Algorithms Package

import { quickSort, binarySearch, dijkstra } from '@ds-algo/algorithms'; // Sorting const numbers = [64, 34, 25, 12, 22, 11, 90]; const sortedNumbers = quickSort(numbers); // Searching const index = binarySearch(sortedNumbers, 25); // Graph algorithms const graph = { A: { B: 4, C: 2 }, B: { A: 4, C: 1, D: 5 } }; const shortestPaths = dijkstra(graph, 'A');

πŸ› οΈ Development

Available Scripts

# Build all packages pnpm run build # Build individual packages pnpm run build --filter @ds-algo/collections pnpm run build --filter @ds-algo/algorithms # Run tests pnpm run test # Run tests for specific package pnpm run test --filter @ds-algo/collections # Development mode with hot reload pnpm run dev # Clean build artifacts pnpm run clean # Format code pnpm run prettier:format # Lint code pnpm run lint

Development Workflow

  1. Adding New Data Structures (Collections package):

    • Create interface in packages/collections/src/interfaces/
    • Create abstract base class in packages/collections/src/abstracts/
    • Create concrete implementation in packages/collections/src/classes/
    • Add tests in packages/collections/tests/
    • Export from packages/collections/src/index.ts
  2. Adding New Algorithms (Algorithms package):

    • Create algorithm file in appropriate category directory
    • Export from category's index file
    • Add comprehensive JSDoc comments with complexity analysis
    • Write unit tests covering various scenarios
    • Update package README with usage examples

Testing Strategy

Each package includes:

  • Unit tests with various input sizes
  • Edge case testing
  • Performance benchmarks
  • Type safety verification
  • Memory usage analysis

πŸ“Š Current Status

Collections Package

  • βœ… Core interfaces implemented (Collection, Iterable, Iterator)
  • βœ… Package structure and build configuration
  • βœ… TypeScript support with comprehensive type definitions
  • πŸ”„ Abstract base classes (in progress)
  • πŸ”„ Concrete implementations (planned)
  • πŸ”„ Collection-specific algorithms (planned)

Algorithms Package

  • βœ… Package structure and build configuration
  • βœ… Comprehensive documentation and roadmap
  • πŸ”„ Sorting algorithms (in progress)
  • πŸ”„ Searching algorithms (in progress)
  • πŸ”„ Graph algorithms (planned)
  • πŸ”„ Dynamic programming solutions (planned)

🎯 Features

Collections Framework

  • Type-safe interfaces with full TypeScript support
  • Generic collections for any data type
  • Iterator pattern for consistent iteration
  • Extensible design for custom implementations
  • Java-inspired architecture for familiarity

Algorithms Library

  • Well-tested implementations with comprehensive test coverage
  • Performance optimized with complexity analysis
  • Multiple algorithm categories (sorting, searching, graph, etc.)
  • TypeScript-first with proper type definitions
  • Educational focus with clear documentation

πŸ“š Documentation

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with proper tests
  4. Ensure all tests pass (pnpm run test)
  5. Submit a pull request

Development Guidelines

  • Follow TypeScript best practices
  • Write comprehensive tests for new features
  • Include JSDoc comments for all public APIs
  • Update relevant documentation
  • Ensure code formatting with Prettier

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Java's Collections Framework
  • Built with modern TypeScript practices
  • Comprehensive testing with Vitest
  • Monorepo management with pnpm workspaces

πŸ“ˆ Roadmap

Short Term (Next 3 months)

  • Implement core collection classes (ArrayList, LinkedList, HashSet)
  • Add basic sorting algorithms (Quick Sort, Merge Sort)
  • Add searching algorithms (Binary Search, Linear Search)
  • Add comprehensive test coverage
  • Add performance benchmarks

Medium Term (3-6 months)

  • Add graph algorithms (Dijkstra, BFS, DFS)
  • Add dynamic programming solutions
  • Add string algorithms
  • Add mathematical algorithms
  • Add algorithm visualization tools

Long Term (6+ months)

  • Add advanced data structures (B-trees, Red-black trees)
  • Add parallel algorithms
  • Add machine learning algorithms
  • Add comprehensive documentation site
  • Add interactive examples and demos

πŸ”— Related Projects


Note: This is an active development project. Check the Issues page for current development status and planned features.