Skip to content

About

A collection of essential data structures implemented in C# to understand and master their core concepts. This repository is perfect for students, developers, and enthusiasts aiming to enhance their coding and problem-solving skills.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Data Structures and Algorithms

Implementations of fundamental data structures and algorithms for learning and practice. The existing data structures are written in C#; the algorithm library provides equivalent implementations in Python, C++, and C#.

This repository is intended for educational use. The implementations favor readability and explicit control flow over standard-library shortcuts.

Algorithms

Category Algorithm Python C++ C# Time complexity
Sorting Insertion sort source source source O(n²)
Sorting Merge sort source source source O(n log n)
Sorting Quicksort source source source O(n log n) average, O(n²) worst
Searching Linear search source source source O(n)
Searching Binary search source source source O(log n)
Graphs Breadth-first search source source source O(V + E)
Graphs Depth-first search source source source O(V + E)
Graphs Dijkstra's shortest path source source source O((V + E) log V)

The sorting functions return a sorted copy and leave their input unchanged. Binary search expects an already sorted sequence. Dijkstra's algorithm accepts non-negative edge weights and returns infinity for unreachable nodes.

Data structures

Structure Implementation Documentation
Singly linked list C# source Guide
Array-backed stack C# source Stack guide
Linked-list stack C# source Stack guide
Hash map Python source Planned work
Queue C# skeletons in queue/ Queue notes

The table distinguishes completed implementations from skeletons; planned data structures are not presented as finished features.

Repository layout

algorithms/
├── cpp/
│   ├── include/problem_solving_algorithms/  # Header-only implementations
│   └── tests/                               # C++ test executable
├── csharp/
│   └── src/ProblemSolving.Algorithms/        # .NET 8 class library
└── python/
    ├── problem_solving_algorithms/          # Importable Python package
    └── tests/                               # unittest suite
Stack/                                       # C# stack project
linkedList/                                  # C# linked-list project
queue/                                       # C# queue project (in progress)
hash/                                        # Python hash map (in progress)
tests/                                       # C# tests

Algorithms are grouped under one top-level directory and then separated by language. The older C# directories retain their current names to avoid breaking the existing solution, project references, and namespaces.

Run the tests

Python requires version 3.12 or newer and has no third-party dependencies:

PYTHONPATH=algorithms/python python -m unittest discover \
  -s algorithms/python/tests -v

Compile and run the C++ tests directly with any C++17 compiler:

g++ -std=c++17 -Wall -Wextra -Wpedantic \
  -I algorithms/cpp/include \
  algorithms/cpp/tests/algorithms_test.cpp \
  -o algorithm_tests
./algorithm_tests

Alternatively, use CMake:

cmake -S algorithms/cpp -B build/algorithms
cmake --build build/algorithms
ctest --test-dir build/algorithms --output-on-failure

Run the existing C# test project with:

dotnet test tests/tests.csproj

The C# algorithm tests live beside the existing stack tests in tests/Unit/.

Quick examples

Python:

from problem_solving_algorithms import binary_search, merge_sort

numbers = merge_sort([8, 2, 5, 1])
position = binary_search(numbers, 5)

C++:

#include <vector>
#include "problem_solving_algorithms/sorting.hpp"

auto numbers = problem_solving::merge_sort(std::vector<int>{8, 2, 5, 1});

C#:

using ProblemSolving.Algorithms;

List<int> numbers = SortingAlgorithms.MergeSort(new[] { 8, 2, 5, 1 });
int position = SearchingAlgorithms.BinarySearch(numbers, 5);

License

Licensed under the terms in LICENSE.txt.

About

A collection of essential data structures implemented in C# to understand and master their core concepts. This repository is perfect for students, developers, and enthusiasts aiming to enhance their coding and problem-solving skills.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages