selcukmart / number-of-connected-groups-y42
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/selcukmart/number-of-connected-groups-y42
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2025-09-17 17:19:27 UTC
README
composer require selcukmart/number-of-connected-groups-y42
Number of connected groups
There are two solutions in it. One of them is non-recursive(custom distance calculation between coordinates technic) only iterable, the other is a classic solution called Depth First Search (DFS) .
The code has unit tests. It can be tested after cloned.
tests/CountForIterativeTest.php
tests/CountForRecursiveTest.php
Iterative Example;
$matrix = [ [1, 1, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1], [1, 0, 0, 0, 0], [1, 0, 1, 0, 1] ]; $result = (new NumberOfConnectedGroupsIterative(5, 5))->countGroups($matrix);
The result will be 5 for only horizontal and vertical links.
DFS Example
$matrix = [ [1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [1, 0, 0, 1, 1], [1, 0, 0, 0, 0], [1, 0, 1, 0, 1] ]; $result = (new NumberOfConnectedGroupsRecursive(5, 5))->countGroups($matrix);
The result will be 5 for only horizontal and vertical links.