• Stars
    star
    237
  • Rank 169,885 (Top 4 %)
  • Language
    C++
  • License
    MIT License
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This repository contains a collection of projects in C++ and Python that implement various data structures and algorithms. The projects are organized by language and topic, and include detailed explanations and examples to help you understand how they work.

Algorithms-And-Data-Structures

GitHub stars GitHub forks GitHub license

This repository contains a collection of projects in C++ and Python that implement various data structures and algorithms. The projects are organized by language and topic, and include detailed explanations and examples to help you understand how they work.

algorithms

About

Ever since I first tackled Algorithms and Data Structures at university in 2015, I've found it super useful to regularly go back to the basics. This becomes even more important when you're trying to learn a new programming language - a strong foundation is key. To help others, I've decided to share my code and notes on the subject with everyone.

My code is written in two programming languages I really enjoy, C++ and Python. I've done my best to stick to the latest best practices. Alongside the code, you'll find the notes I made while learning. These notes give more context and could be really handy for anyone new to Algorithms and Data Structures.

Requirements

The following requirements are necessary to build and run the code in this repository:

  • For C++ projects:
    • A C++ compiler supporting C++14
    • CMake 3.15 or later
  • For Python projects:
    • Python 3.10 or later

No additional libraries or modules are required.

Running the Examples

This repository is organized into distinct algorithm implementations, each contained in its own subdirectory. These subdirectories provide the source code, unit tests, and build configuration files necessary for each algorithm. Because each algorithm forms a separate project, you should handle the build and test processes individually.

Building and Testing C++ Projects

Building and testing C++ projects involve a sequence of steps. Here's a detailed walkthrough:

  1. Navigate to the project directory: Start by moving into the directory containing the specific project you want to build and test.

  2. Create and navigate into the build directory:

mkdir -p build && cd build

This command creates a new directory named build (if it doesn't already exist) and then navigates into it. The build directory is where the output files of the build process will be stored.

  1. Generate the build files with CMake:
cmake ..

This command runs CMake to generate the build files. .. tells CMake to look for the CMakeLists.txt file in the directory above build.

  1. Build the project:
make

This command compiles the source code using the instructions specified in the CMakeLists.txt file.

  1. Run the unit tests:
ctest --verbose

The ctest --verbose command executes the unit tests and uses the verbose flag to provide a detailed output.

Testing Python Projects

To test a Python project, execute the following command in the project directory:

python -m unittest discover -v

This command uses Python's built-in unittest module to discover and run the tests. The -v (verbose) flag is used to get more detailed output from the tests.

Using the Testing Utility Script

For convenience, this repository includes a utility script named run_tests.sh. Execute the following commands from the repository's root to run tests in all subprojects:

  • To run all unit tests: ./run_tests.sh
  • To run all Python tests: ./run_tests.sh --python
  • To run all C++ tests: ./run_tests.sh --cpp
  • To read all options from terminal: ./run_tests.sh --help

Code Formatting Conventions

Consistent code formatting is essential for maintaining readability and understanding of the codebase. Therefore, we have adopted specific formatting guidelines for each programming language used in this repository.

C++ Formatting

We adhere to the Google C++ Style Guide. To automatically format the code, we use clang-format. Use the following command to format your code:

find . -regex '.*\\.(cpp|hpp|cu|c|h)' -exec clang-format -style=file -i {} \\;

This command recursively finds all files with .cpp, .hpp, .cu, .c, or .h extensions and formats them using clang-format.

CMake Formatting

CMake files should have a consistent style as well. For this, we use cmake-format. To format a CMakeLists.txt file, execute the following command:

cmake-format CMakeLists.txt -i

This command applies the cmake-format to the CMakeLists.txt file.

Python Formatting

We follow the PEP 8 - Style Guide for Python Code for Python projects and use black to automatically format the code. Use the following command to format your Python code:

black .

This command formats all Python files in the current directory and its subdirectories using black.

Notes

List of projects

Data structures

# Structure Implementation
1 Linked List Python Cpp
2 Vector Python Cpp
3 Stack Python Cpp
4 Queue Python Cpp
5 Heap Python Cpp
6 Binary Search Tree Python Cpp
7 Avl Tree Python Cpp
8 Red Black Tree Python Cpp
9 Hash Table Python Cpp

Graphs

# Algorithm Implementation
1 General graph Python Cpp
1 Is Bipartite? Python Cpp
2 BFS Python Cpp
3 DFS Python Cpp
4 Dijkstra Python Cpp
5 A* Python Cpp
6 Bellman-Ford Python Cpp
7 Kruskal Python Cpp
8 Prim Python Cpp

Backtracking

# Problem Solution
1 Permutations Python Cpp
2 Combinations Python Cpp
3 String Pattern Python Cpp
4 Generating words Python Cpp
5 K-colorable configurations Python Cpp
6 Hamiltonian paths Python Cpp
7 Knigt tour Python Cpp
8 Topological orderings Python Cpp
9 Tic-tac-toe (minimax) Python Cpp

Dynamic Programming

# Problem Solution
1 Fibonacci Python Cpp
2 Grid travelers Python Cpp
3 Stairs Python Cpp
4 Can sum Python Cpp
5 How sum Python Cpp
6 Best sum Python Cpp
7 Can construct Python Cpp
8 Count construct Python Cpp
9 All construct Python Cpp
10 Coins Python Cpp
11 Longest increasing subsequence Python Cpp
12 Longest common subsequence Python Cpp
13 Knuth-Morris-Pratt Python Cpp
14 Minimum insertions to form a palindrome Python Cpp

Sorting

# Algorithm Implementation
1 Insertion sort Python Cpp
2 Selection sort Python Cpp
3 Heap sort Python Cpp
4 Merge sort Python Cpp
5 Quick sort Python Cpp

Brain Teasers

# Problem Solution
1 Minimum deletions to make valid parentheses Python Cpp
2 Is palindrome after at most one char deletion? Python Cpp
3 K closest points to origin Python Cpp
4 Subarray sum equals K Python Cpp
5 Add numbers given as strings Python Cpp
6 Dot product of two sparse vectors Python Cpp
7 Range sum of BST Python Cpp
8 Product of array except self Python Cpp
9 Convert BST to sorted doubly linked list Python Cpp
10 Lowest common ancestor of a binary tree Python Cpp
11 LRU Cache Python Cpp
12 Randomize An Array Python Cpp
13 Binary Tree Right Side View Python Cpp
14 Design Browser History Python Cpp
15 Score After Flipping Matrix Python Cpp

References

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

More Repositories

1

Bash-Scripts

A collection of Bash scripts for automating routine tasks and streamlining your workflow.
Shell
140
star
2

Qt-Widgets

A collection of examples and reusable elements created with Qt6 widgets.
Python
76
star
3

Vtk-Examples

Explore the world of 3D graphics and visualization with VTK examples in Python.
Python
25
star
4

Linux-Notes

Compiled guides and notes on various topics related to Linux. The content is organized into sections and subsections, making it easy to navigate regardless of your experience level - beginner or advanced.
22
star
5

Frontend-Notes

Hello and thanks for stopping by! This is my personal treasure trove where I stash all sorts of notes, tips, and tricks about frontend development. Whether you're starting out, scaling up your skills, or just in need of a quick reference, you're in the right place.
HTML
19
star
6

Lightpad

Welcome to Lightpad, a powerful and intuitive code editor developed with the Qt framework. Lightpad is designed to make it easy for you to write, edit, and debug code in a variety of languages.
C++
17
star
7

Databases-Notes

This repository is a helpful guide for anyone working with data. It covers everything you need to know about databases, including SQL and NoSQL databases, making them faster, and keeping them secure. It also has real-world examples to help you understand how to use databases in practice.
Python
13
star
8

Kurs-Podstaw-Pythona

Je艣li chcesz rozpocz膮膰 nauk臋 programowania w j臋zyku Python, ten kurs b臋dzie doskona艂ym wyborem. Kurs jest starannie podzielony na cztery sekcje, co umo偶liwia stopniowe przyswajanie wiedzy i umiej臋tno艣ci niezb臋dnych do opanowania tego j臋zyka. Dzi臋ki temu, krok po kroku, zdob臋dziesz solidne podstawy oraz zaawansowane techniki programowania w Pythonie
Python
12
star
9

Parallel-And-Concurrent-Programming

Concurrent and parallel programming might seem complex, but this guide simplifies it. Learn about sequential vs non-sequential programming, processes, and threads. Explore examples in popular languages like C++, Python, and JavaScript to apply your new knowledge to your projects.
C++
8
star
10

Backend-Engineers-Guide

This repository is a collection I've put together, focusing on various backend engineering topics. It's a place where you can find information on API design, databases, deployment, distributed computing, networking, performance optimization, security, and even more specialized areas.
6
star
11

Numerical-Methods

This repository offers a comprehensive collection of numerical methods implemented in Python. It includes solutions to various mathematical problems, detailed explanations of each method, illustrative examples, and comparisons with prominent scientific libraries like Numpy, Scikit-Learn, and SciPy.
Jupyter Notebook
5
star
12

Computational-Fluid-Dynamics-CFD-Resources

This repository is a comprehensive collection of advanced resources for Computational Fluid Dynamics (CFD). It includes in-depth notes, specialized scripts, and detailed tutorials covering various CFD tools like ParaView, Gmsh, and more. Aimed at both beginners and experienced practitioners, it serves as a platform for learning and exploration.
Python
3
star
13

Testio

Testio is a simple and efficient testing framework that uses multiprocessing to verify the standard output of applications. With Testio, you can quickly and easily write tests to ensure that your applications are functioning as expected.
Python
3
star
14

Od-C-do-Cpp

Kod 藕r贸d艂owy do program贸w z yt.
C++
2
star
15

Coding-Interviews

My alternative solutions to challenges from Harry He's book "Coding Interviews."
C++
2
star
16

Nauka-Programowania

Je艣li chcesz nauczy膰 si臋 programowa膰, ale nie wiesz od czego zacz膮膰, to trafi艂e艣 we w艂a艣ciwe miejsce. Ten projekt oferuje zbi贸r zada艅, kt贸re przeprowadz膮 Ci臋 przez wszystkie koncepcje potrzebne do zrozumienia w programowaniu.
Java
2
star
17

10-Days-Statistics

10 days statistics challenge from hackerrank
Python
2
star
18

Proste-Projekty

Zbi贸r porad i zasob贸w dla pocz膮tkuj膮cych programist贸w, zawieraj膮cy szczeg贸艂owe wytyczne oraz przyk艂ady realizacji projekt贸w.
Python
2
star
19

Camac

Witamy w repozytorium Ko艂a Naukowego CAMAC, kt贸re gromadzi zasoby edukacyjne oraz materia艂y ze spotka艅 naukowych z lat 2018-2019. Repozytorium jest przeznaczone dla student贸w Wydzia艂u Fizyki Politechniki Warszawskiej zainteresowanych tematami zwi膮zanymi z informatyk膮 stosowan膮.
Python
2
star
20

Think-Python

My alternative solutions to the challenges from Allen B. Downey's book "Think Python".
Python
2
star
21

Simulation-Covid

This is my attempt at modeling and simulating Covid-19's spread.
C++
1
star
22

Personal-Website

Welcome to the GitHub repository for adamdjellouli.com. Your feedback, comments, and suggestions for improvements are highly appreciated. Your support is invaluable to me.
HTML
1
star
23

Arduino

Small Arduino projects
C++
1
star
24

Git-Notes

This repository contains notes on various topics related to Git. The notes are intended to be a reference for Git commands and concepts, and are organized by topic.
1
star
25

Numpy-Tutorials

Welcome to the NumPy Tutorials repository, your one-stop collection of learning materials for mastering NumPy, a fundamental library for scientific computing in Python.
Jupyter Notebook
1
star
26

Stanford-Machine-Learning

Welcome to the Stanford Machine Learning course! This course, taught by Professor Andrew Ng, provides a comprehensive introduction to the field of machine learning. Through a combination of lectures, exercises, and projects, you will learn the fundamental techniques needed to build and apply machine learning models to real-world problems.
Jupyter Notebook
1
star
27

Markdown-Image-Generator

The Markdown Image Generator is a Python-based project that transforms Markdown documents into a series of images. It aims to provide a unique way to visualize Markdown content, especially useful for presentations, sharing over image-based platforms, or even for educational purposes.
Python
1
star
28

Coin-Detection

Training and using a machine learning model locally to accurately identify and count coins in a given image. This project includes data preprocessing, model training, and evaluation to ensure precise coin detection and counting.
Python
1
star
29

Design-Patterns-General-Overview

A comprehensive collection of the most popular design patterns and their implementations, designed to help you understand and apply these essential patterns in your software development projects. This repository covers a wide range of design patterns, providing clear explanations, practical examples, and code implementations in various languages.
Python
1
star