diogoca/dsalgorithms

There is no license information available for the latest version (dev-master) of this package.

Data Structures, Search, Sort, Numbers and String Algorithms

dev-master 2020-07-06 23:10 UTC

This package is auto-updated.

Last update: 2024-09-07 08:10:43 UTC


README

Data Structures and Search, Sort, Numbers, String Algorithms implemented using PHP, the goal of this project it's the study and practice of them. Please let me know any mistake opening an issue.

Installation

It's recommended that you use Composer to install.

$ composer require diogoca/dsalgorithms

Using

ArrayList

$list = new \DsAlgorithms\Ds\DsList\ArrayList();
$list->add('foo');
$list->add('bar');
$list->add('x');
$list->add('y');
$list->add('z');

echo $list . PHP_EOL; # [foo, bar, x, y, z]
echo $list->get(1) . PHP_EOL; # bar
$list->remove(2);
echo $list . PHP_EOL; # [foo, bar, y, z]

Search

Comparing what algorithm do less calls.

use DsAlgorithms\Search\BinarySearch;
use DsAlgorithms\Search\SequentialSearch;

$arr = \range(7, 14);
$arrCopy = $arr;

print_r($arr);

echo '14 in index ' . BinarySearch::search($arr, 14) . PHP_EOL;
echo 'binary search calls ' . BinarySearch::$calls . PHP_EOL; 

echo '14 in index ' . SequentialSearch::search($arr, 14) . PHP_EOL; 
echo 'sequencial search calls ' . SequentialSearch::$calls . PHP_EOL;

Running from bash

$ php public/index.php src/String/MaximumOccurringCharacter.php

Notes

  • On DsAlgorithms\Ds\DsList namespace I'm not using List as name once that's a PHP reserved word
  • I'm using \SplFixedArray once that on PHP I can't create an array with fixed size