Giter Site home page Giter Site logo

doganoo / phpalgorithms Goto Github PK

View Code? Open in Web Editor NEW
936.0 40.0 92.0 527 KB

A collection of common algorithms implemented in PHP. The collection is based on "Cracking the Coding Interview" by Gayle Laakmann McDowell

License: MIT License

PHP 100.00%
php php7 algorithm algorithms gayle-laakmann-mcdowell datastructures lists maps cracking-the-coding-interview

phpalgorithms's People

Contributors

berezuev avatar doganoo avatar flavioheleno avatar krlv avatar tuqqu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpalgorithms's Issues

implement BinaryTree

Is your feature request related to a problem? Please describe.
BinaryTree extends actually BinarySearchTree. Needs to be implemented

PDOException when trying to serialize an instance of PDO in MapUtil

Expected Behavior

creating an index for HashMap class

Current Behavior

throws an PDOException with message: You cannot serialize or unserialize PDO instances

Possible Solution

??

Steps to Reproduce

  1. create HashMap / HashSet instance
  2. add class that is/has instance of PDO

add declare(strict_types=1) to each file and test

As PHPAlgorithms should be type safe, we should add strict_types declaration to each file. Doing this, we need to ensure that current functionality is still given (method calls, unit tests).

It would also be glad to create unit tests for each file that does not have a test, but not a must-have yet.

subList() in ArrayList does not work as expected

The subList() method in ArrayList class does not work as expected. When slicing an array list at an index, the slicing should happen from 0 to index and from index+1 to the end.

Expected Behavior

slice properly

Current Behavior

slices at a wrong index

Possible Solution

Steps to Reproduce

$anyList = new ArrayList();
$anyList->add(1);
$anyList->add(2);
$anyList->add(3);
$anyList->add(4);
$anyList->add(5);

$upperList = $anyList->subList(0, $index);
$lowerList = $anyList->subList($index+1, $anyList->length());

$list = new ArrayList();
$list->addAll($upperList);
$list->add($value);
$list->addAll($lowerList);

print_r($list);

Possible Implementation

not tested, but in subList() method:

$array = \array_slice($this->array, $start, $end - $start -1, true);

Wrong comparison expression in String Permutations

There is a wrong comparison in Permutation.php#L54, requiring a call to permutation for single character string permutations.

Expected Behavior

Single character string permutations should return early in Permutation.stringPermutations.

Current Behavior

Single character string permutations require a call to permutation, adding a minor overhead to Permutation.stringPermutations.

Possible Solution

Replace (1 === $string) with (1 === $strLen).

Steps to Reproduce

  1. Disable the private function Permutation.permute
  2. Run the code below
use doganoo\PHPAlgorithms\Algorithm\Various\Permutation;

$permutation  = new Permutation();
$permutations = $permutation->stringPermutations("a");

Context (Environment)

I was reviewing the code out of curiosity and found the issue.

Broken TimSort class

Describe the bug
According to #22, the TimSort sorting algorithm is broken under certain circumstances.

To Reproduce
Check the PR code which tests broken code

extend tests

add new unit tests and extend to cover all cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.