selcukmart/number-of-connected-groups-y42
Composer 安装命令:
composer require selcukmart/number-of-connected-groups-y42
包简介
README 文档
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.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-17