Skip to main content

Prerequisites

Before you begin, ensure you have the following installed on your system:
  • Node.js (version 14 or higher)
  • npm (comes with Node.js)
  • Git (for cloning the repository)

Clone the Repository

1

Fork the repository

Visit the GitHub repository and click the Fork button in the top-right corner to create your own copy.
2

Clone your fork

Clone the repository to your local machine:
git clone https://github.com/YOUR_USERNAME/data-structures-and-algorithms.git
Replace YOUR_USERNAME with your GitHub username.
3

Navigate to the directory

Change into the project directory:
cd data-structures-and-algorithms

Install Dependencies

Install the required npm packages:
npm install
This will install all the development dependencies defined in package.json, including:
  • TypeScript - For type-safe code compilation
  • Jest - Testing framework
  • @swc/jest - Fast TypeScript/JavaScript transpiler
  • jest-extended - Additional Jest matchers

Verify Installation

To verify that everything is set up correctly, compile the TypeScript code and run the test suite:
npm test
You should see output indicating that TypeScript compilation succeeded and all tests are passing:
✓ Compilation successful
✓ Test Suites: XX passed, XX total
✓ Tests:       XXX passed, XXX total
The first test run may take a few moments as TypeScript compiles all the source files.

Project Structure

Once installed, your project directory will have the following structure:
data-structures-and-algorithms/
├── algorithms/
│   ├── sorting/              # Sorting algorithms
│   ├── searching/            # Searching algorithms
│   ├── shortest-path/        # Graph algorithms
│   └── design-techniques/    # Algorithm design patterns
├── data-structures/
│   ├── array/
│   ├── lists/                # Linked lists
│   ├── stack/
│   ├── queue/
│   ├── trees/                # Tree structures
│   └── graph/
├── node_modules/             # Dependencies
├── jest.config.js            # Jest configuration
├── package.json              # Project metadata
├── tsconfig.json             # TypeScript configuration
└── README.md                 # Project documentation

TypeScript Configuration

The project uses TypeScript with strict type checking enabled. You can find the TypeScript configuration in tsconfig.json. To compile TypeScript files manually:
npx tsc
This will compile all .ts files according to the configuration and output JavaScript files.

Development Workflow

Now that you have the project set up, you can:
  1. Explore the code - Browse through the algorithms/ and data-structures/ directories
  2. Run tests - Execute npm test to run all tests or target specific tests (see Running Tests)
  3. Make changes - Modify existing implementations or add new ones
  4. Verify changes - Run tests to ensure your changes work correctly

Next: Running Tests

Learn how to run tests and target specific data structures or algorithms

Troubleshooting

TypeScript Compilation Errors

If you encounter TypeScript compilation errors, ensure you’re using a compatible version:
npx tsc --version
The project requires TypeScript 5.3.3 or higher.

Test Failures

If tests fail unexpectedly:
  1. Ensure all dependencies are installed: npm install
  2. Clear Jest cache: npx jest --clearCache
  3. Re-run the tests: npm test

Node Version Issues

If you encounter compatibility issues, check your Node.js version:
node --version
Consider using nvm (Node Version Manager) to manage multiple Node.js versions.

Next Steps

Running Tests

Learn how to run and target specific tests

Data Structures

Explore the implemented data structures

Build docs developers (and LLMs) love