From 0a7afbaad737b0ff66632241f3fef92f0ea9a55f Mon Sep 17 00:00:00 2001 From: Mizanur Rahman Date: Mon, 13 Jan 2020 23:18:16 +0900 Subject: [PATCH 1/4] Create FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..53253a8 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms +github: [mirahman] +custom: ["paypal.me/mirahman1221", mizanurrahman.com] From 54e88a3f7dad9d51254ea0cb27732c7e9fc1a554 Mon Sep 17 00:00:00 2001 From: Mizanur rahman Date: Thu, 16 Jan 2020 19:15:25 +0600 Subject: [PATCH 2/4] adding TRIE data structure in PHP --- DS/Tree/.DS_Store | Bin 0 -> 6148 bytes DS/Tree/Classes/Trie.php | 49 +++++++++++++++++++++++++++++++++++ DS/Tree/Classes/TrieNode.php | 21 +++++++++++++++ DS/Tree/Examples/trie.php | 30 +++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 DS/Tree/.DS_Store create mode 100644 DS/Tree/Classes/Trie.php create mode 100644 DS/Tree/Classes/TrieNode.php create mode 100644 DS/Tree/Examples/trie.php diff --git a/DS/Tree/.DS_Store b/DS/Tree/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1ad25cbe90a6572f8b80a99612b73f93e916116c GIT binary patch literal 6148 zcmeHKJ5B>Z41I=3M50MaIalBYqYzHO1t0{fm9|*XZ^gNCG@d_-6gJS&py!qSW<0h> z`-=4%fNehx_rM0gn(By8H%swz*M(e_$I+t3gf~ow>2=tTi|ES^&%MC|2E1V6bIKnF zmi&J7&f5Dik1p4fR}6>&F(3xSfEf6l0dKIB^=+c87!U(u;KYD`9~#xM7tV?C>7a=b zfViSNgzK0kh|L|uUN|SxL$ORHW~$YQVVO>UtGHe`CuTYV!&3rr`?vXRK0caa^7nj^_l81N2&|gkwO#g lm>BJt8*j&V5tMPw*F5iqb7G{^AL&H>3^*?mG4R(6d;tOm8=L?D literal 0 HcmV?d00001 diff --git a/DS/Tree/Classes/Trie.php b/DS/Tree/Classes/Trie.php new file mode 100644 index 0000000..2fe2292 --- /dev/null +++ b/DS/Tree/Classes/Trie.php @@ -0,0 +1,49 @@ + + * + */ + +namespace DS\Tree\Classes; + +use DS\Tree\Classes\TrieNode; + +class Trie +{ + public $root; + public function __construct() + { + $this->root = new TrieNode; + } + + public function insert(string $key) + { + $key = strtolower($key); + $length = strlen($key); + $pCrawl = $this->root; + for ($level = 0; $level < $length; $level++) { + $index = ord($key[$level]) - ord('a'); + if (is_null($pCrawl->children[$index])) + $pCrawl->children[$index] = new TrieNode(); + + $pCrawl = $pCrawl->children[$index]; + } + $pCrawl->isEndOfWord = true; + } + + public function search(string $key) + { + $key = strtolower($key); + $length = strlen($key); + $pCrawl = $this->root; + for ($level = 0; $level < $length; $level++) { + $index = ord($key[$level]) - ord('a'); + if (is_null($pCrawl->children[$index])) + return false; + + $pCrawl = $pCrawl->children[$index]; + } + return (!is_null($pCrawl) && $pCrawl->isEndOfWord); + } +} diff --git a/DS/Tree/Classes/TrieNode.php b/DS/Tree/Classes/TrieNode.php new file mode 100644 index 0000000..ee49527 --- /dev/null +++ b/DS/Tree/Classes/TrieNode.php @@ -0,0 +1,21 @@ + + * + */ + +namespace DS\Tree\Classes; + +class TrieNode +{ + public $children; + public $isEndOfWord; + const ALPHABETSIZE = 26; + + public function __construct() + { + $this->isEndOfWord = false; + $this->children = array_fill(0,self::ALPHABETSIZE, null); + } +} \ No newline at end of file diff --git a/DS/Tree/Examples/trie.php b/DS/Tree/Examples/trie.php new file mode 100644 index 0000000..23e9ab0 --- /dev/null +++ b/DS/Tree/Examples/trie.php @@ -0,0 +1,30 @@ + + * + */ + +include __DIR__ . '/../../../Vendor/Autoload.php'; + +use \DS\Tree\Classes\Trie; + +try { + $keys = ["dhaka", "bangladesh", "there", "answer", "any", "by", "bye", "their"]; + + $trie = new Trie(); + // Construct trie + for ($i = 0; $i < count($keys); $i++) + $trie->insert($keys[$i]); + + $searches = ["dhaka", "three", "these", "there", "the", "any", "DHAKA", "anyone", "desh"]; + foreach ($searches as $search) { + if ($trie->search($search)) { + echo "$search - is present in the trie \n"; + } else { + echo "$search - is not present in the trie \n"; + } + } +} catch (Exception $e) { + echo $e->getMessage(); +} From 7574f25f96c6b77bf036fcf2a8ef560719d0e21e Mon Sep 17 00:00:00 2001 From: Mizanur rahman Date: Thu, 16 Jan 2020 19:26:03 +0600 Subject: [PATCH 3/4] added Trie in our list of solved DS --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45417a4..057c7ab 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Any feedback, bugs or suggestion will be welcomed. - Binary Tree - Binary Search Tree - Tree Traversal (In-order, pre-order, post-order) + - Trie (Simple insert and search operation) 5. Heaps From eee6c1b6164c2a74295bd75ed38f13cbbc903971 Mon Sep 17 00:00:00 2001 From: Mizanur Rahman Date: Fri, 21 Feb 2020 05:20:12 +0600 Subject: [PATCH 4/4] Create .sonarcloud.properties --- .sonarcloud.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 .sonarcloud.properties diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1 @@ +