Skip to content

brandenge/data-structures-and-algorithms

Repository files navigation

Data Structures and Algorithms

These are my node-based implementations of common data structures and algorithms.

All implementations are done in Python, with some additional implementations also available in JavaScript.

Also includes full test suites and test coverage reports using Pytest and Jest, respectively.

Features:

Python

Data Structures

Graphs

Hash Tables

Trees

Linear Data Structures

Algorithms

Searching

Search Algorithms

  • Linear Search
  • Binary Search

Sorting

Sorting Algorithms

  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Merge Sort
  • Quicksort, with a simplified implementation and a random pivot
  • Quicksort, with Lomuto partitioning and Sedgewick's median-of-three pivot choice
  • Quicksort, with Hoare partitioning and 2 different versions with different pivot choices

Other

  • Fibonacci Sequence - using dynamic programming in different variations, including memoization via a closure and a space-optimized, bottom-up iterative approach.
  • Generators

To Do List

  • Additional Implementations:
    • Finding the height of a tree
    • Finding the depth of a node in a tree
    • Validating if a tree is balanced
    • Array-based implementations of trees
  • Additional Data Structures:
    • Dynamic Array
    • Priority Queue
    • Double-ended Queue
    • Binary Heap
    • Trie
    • Binary space partitioning tree
    • Self-Balancing Trees:
      • Red-Black Tree
      • AVL Tree
      • B-tree
  • Additional Graph Algorithms:
    • Dijkstra's algorithm:
      • using an array for unvisited nodes (simplified implementation)
      • using a priority queue for unvisited nodes (optimized implementation)
    • Bellman-Ford algorithm (for weighted graph with negative weights)
    • Backtracking algorithm
    • Minimum spanning tree (MST)
    • Floyd-Warshall algorithm
    • Graph coloring
    • Bidirectional sort
    • Topological sort
  • Additional Sorting Algorithms
    • Bucket sort
    • Heapsort
    • Timsort - more efficient for doing multiple sorting passes by taking advantage of the current ordering
    • Radix sort
    • Counting sort
    • Shellsort
    • Implement stable versions of unstable sorting algorithms
  • Other Algorithms
    • Quickselect (search)
    • Golomb Sequence
    • Unique paths problem

JavaScript

Data Structures

Graphs

Hash Tables

Trees

Linear Data Structures

Algorithms

Sorting

Other

Testing

Python

From the python directory:

  • Run pytest or coverage run -m pytest to run the full test suite for Python implementations.
  • Run open htmlcov/index.html after running the test suite to see the coverage report in the browser.
  • Run coverage run -m pytest -k <test_name> to run an individual test.

Python Test Coverage Report Part 1 Python Test Coverage Report Part 2 Python Test Output

JavaScript

From the javascript directory:

  • Run npm test to run the full test suite for JavaScript implementations.

JavaScript Test Coverage Report

Notes To Self for Future Implementations

  • Many data structure methods require direct access to node objects. Instead of abstracting away the node class for reuse, try coupling separate node classes to each data structure class in future implementations. This might improve encapsulation of the data structure class.
  • Try implementing dunder methods for each data structure, such as __iter__ and __next__ for iteration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors