A repository with implementations of different data structures and algorithms using PHP

Overview

PHP Data Structures and Algorithms

Data structure and Algorithm is always important for any programming language. PHP, being one of the most popular language for web development, also requires the pure data structure and algorithm implementations.

In this project, i am trying to cover major data structure and algorithm implementations using PHP 7. For more details discussion about the topics, you can read my book , https://www.amazon.com/PHP-7-Data-Structures-Algorithms/dp/178646389X/

Any feedback, bugs or suggestion will be welcomed.

Topics covered

  1. Linked List

    • Single Linked list
    • Circular Linked list
    • Doubly Linked List
  2. Stacks

    • Stack using Array
    • Stack using Linked List
  3. Queues

    • Queue using Array
    • Queue using Linked List
    • Priority Queue
    • Circular Queue
    • Double Ended Queue - DeQueue
  4. Trees

    • Generic Tree
    • Binary Tree
    • Binary Search Tree
    • Tree Traversal (In-order, pre-order, post-order)
    • Trie (Simple insert and search operation)
  5. Heaps

    • Min Heap
    • Max Heap
  6. Graph

    • BFS
    • Bellman Ford Algorithm
    • DFS
    • Dijkstra
    • Floyd Warshall
    • Kruksal
    • Prim Minimum Spanning tree
    • Topological Sorting
  7. Sorting

    • Bubble sort
    • Bubble Sort with improvements
    • Bucket sort
    • Heap Sort
    • Insertion Sort
    • Merge Sort
    • Quick Sort
    • Radix Sort
    • Selection Sort
  8. Searching

    • BFS
    • Binary Search (Iterative)
    • Binary Search (Recursive)
    • DFS
    • DFS using Stack
    • Exponential Search
    • Interpolation Search
    • Repetitive Binary Search
  9. Dynamic Programming and Others

    • Sudoku (Backtracking)
    • Collaborative Filtering
    • DNA Sequencing (NeedlemanWunsch Algorithm)
    • 0/1 KnapSack Dynamic Programming
    • Fibonacci (Recursive)
    • Fibonacci (Memoized)
    • Huffman Encoding (Greedy Algorithm)
    • Job Scheduler (Greedy Algorithm)
    • KMP String matching algorithm
    • Longest Common Subsequences (LCS)
    • Pattern Matching
    • Sparse Array
  10. Numbers and Maths - PHP Big Integer Implementation - Prime number generation - Sieve

I know lots of things are missing in the list? Would you mind to let me know what you wanna see implemented? I will priortize those and add here.

Coming Soon

  • AVL tree implemenations
  • Project Euler Solutions in PHP for Hackerrank.com
  • More algorithms
You might also like...
PHP Integrated Query, a real LINQ library for PHP

PHP Integrated Query - Official site What is PINQ? Based off the .NET's LINQ (Language integrated query), PINQ unifies querying across arrays/iterator

CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages

CRUDlex CRUDlex is an easy to use, well documented and tested CRUD generator for Symfony 4 and Silex 2. It is very useful to generate admin pages for

World countries in JSON, CSV, XML and Yaml. Any help is welcome!

World countries in JSON, CSV, XML and YAML. Countries data This repository contains a list of world countries, as defined by ISO Standard 3166-1, in J

Best FlexForm based content elements since 2012. With TCA mapping feature, simple backend view and much more features which makes it super easy to create own content element types.
Best FlexForm based content elements since 2012. With TCA mapping feature, simple backend view and much more features which makes it super easy to create own content element types.

DCE-Extension for TYPO3 What is DCE? DCE is an extension for TYPO3 CMS, which creates easily and fast dynamic content elements. Based on Extbase, Flui

A Collections library for PHP.

A Library of Collections for OO Programming While developing and helping others develop PHP applications I noticed the trend to use PHP's arrays in ne

Yet Another LINQ to Objects for PHP [Simplified BSD]

YaLinqo: Yet Another LINQ to Objects for PHP Online documentation GitHub repository Features The most complete port of .NET LINQ to PHP, with many add

🗃 Array manipulation library for PHP, called Arrayy!

🗃 Arrayy A PHP array manipulation library. Compatible with PHP 7+ & PHP 8+ \Arrayy\Type\StringCollection::create(['Array', 'Array'])-unique()-appen

`LINQ to Object` inspired DSL for PHP

Ginq Array handling in PHP? Be happy with Ginq! Ginq is a DSL that can handle arrays and iterators of PHP unified. Ginq is inspired by Linq to Object,

Collections Abstraction library for PHP

Collections Collections Abstraction library for PHP The Collection library is one of the most useful things that many modern languages has, but for so

Comments
  • Create examples in SPL or DS

    Create examples in SPL or DS

    I was taking a look at your examples and I really enjoyed it. However, I have seen that you do many things manually which can be simplified with some things that PHP has in SPL and DS, what do you think if we create examples using their libs?

    I think it's a really good idea because you have a lot of examples, thing PHP don't have. If we can create more examples and in the future create a documentation and define the documentation and examples in PHP docs.

    The data structures are really essential, we need start talk more about that!

    opened by omarkdev 1
  • error in dijkstra() function

    error in dijkstra() function

    When I set the $source = "F" and $target = "E" to dijkstra() function, the function return 5 and path is F-E. The true result must 4 and path is F-D-E

    opened by NgVanDuy 1
  • Method insertBefore in LinkedList and the first element.

    Method insertBefore in LinkedList and the first element.

    Hello!

    Method insertBefore doesn't work correctly with the first element in a list. You can't insert before the first element.

    Test case:

    $l = new \DS\LinkedList\Classes\LinkedList();
    $l->insert("1");
    $l->insert("2");
    $l->insert("3");
    
    $l->insertBefore('0','1');
    $l->display();
    

    Expected:

    Total Nodes: 4
    0
    1
    2
    3
    

    Actual:

    Total Nodes: 4
    1
    2
    3
    
    opened by stanislavkrsv 0
Owner
Mizanur Rahman
I am a software artisan with great passion on building large scale applications. I am an agile practitioner and coach/trainer of agile engineering practices.
Mizanur Rahman
A community driven collection of sorting algorithms in PHP

algorithms A community driven collection of sorting algorithms This repository includes a comma separated file that includes 10k numbers between 1 and

Andrew S Erwin 0 May 16, 2022
Output complex, flexible, AJAX/RESTful data structures.

Fractal Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with J

The League of Extraordinary Packages 3.5k Jan 8, 2023
Map nested JSON structures onto PHP classes

JsonMapper - map nested JSON structures onto PHP classes Takes data retrieved from a JSON web service and converts them into nested object and arrays

Christian Weiske 1.4k Dec 30, 2022
JsonMapper - map nested JSON structures onto PHP classes

Takes data retrieved from a JSON web service and converts them into nested object and arrays - using your own model classes.

Netresearch 9 Aug 21, 2022
:lipstick: Scalable and durable all-purpose data import library for publishing APIs and SDKs.

Porter Scalable and durable data imports for publishing and consuming APIs Porter is the all-purpose PHP data importer. She fetches data from anywhere

null 594 Jan 1, 2023
Library for (de-)serializing data of any complexity (supports JSON, and XML)

jms/serializer Introduction This library allows you to (de-)serialize data of any complexity. Currently, it supports XML and JSON. It also provides yo

Johannes 2.2k Jan 1, 2023
Missing data types for PHP. Highly extendable.

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

SmartEmailing 82 Nov 11, 2022
Changeset calculator between two states of a data

Totem \\\\//// |.)(.| | || | Changeset calculator between two state of a data \(__)/ Requires PHP 5.4 ; Compatible

Wisembly 75 May 6, 2021
True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code. Uses the accepted Fibers RFC to be implemented into PHP 8.1

PHP Fibers - Async Examples Without External Dependencies True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code behemoth

Cole Green 121 Jan 6, 2023
Leetcode for PHP, five questions a week and weekends are updated irregularly

✏️ Leetcode for PHP why do you have to sleep for a long time ,and naturally sleep after death 联系 说明 由于目前工作主要是 golang,我又新起了一个LeetCode-Go-Week项目,- Leetc

吴亲库里 370 Dec 29, 2022