From 8ad75baa16e6eccde3da522ad6c179e360c669c8 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Wed, 2 Oct 2024 20:11:26 +0530 Subject: [PATCH 1/8] Improve TrieImp.java comments & enhance readability --- .../datastructures/trees/TrieImp.java | 195 +++++++++++++----- 1 file changed, 138 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java index d166653ff1b4..61a73598383b 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java @@ -3,138 +3,219 @@ import java.util.Scanner; /** - * Trie Data structure implementation without any libraries + * Trie Data structure implementation without any libraries. + *

+ * The Trie (also known as a prefix tree) is a special tree-like data structure + * that is used to store a dynamic set or associative array where the keys are + * usually strings. It is highly efficient for prefix-based searches. + *

+ * This implementation supports basic Trie operations like insertion, search, + * and deletion. + *

+ * Each node of the Trie represents a character and has child nodes for each + * possible character. * * @author Dheeraj Kumar Barnwal */ public class TrieImp { + /** + * Represents a Trie Node that stores a character and pointers to its children. + * Each node has an array of 26 children (one for each letter from 'a' to 'z'). + */ public class TrieNode { + // Array to store references to child nodes, one for each letter of the alphabet + // (a-z) TrieNode[] child; - boolean end; + boolean end; // Flag to indicate if this node marks the end of a valid word + + /** + * Constructor to initialize a TrieNode with an empty child array and set end to + * false. + */ public TrieNode() { - child = new TrieNode[26]; - end = false; + child = new TrieNode[26]; // Initialize child array with 26 slots (for each letter a-z) + end = false; // By default, this node doesn't mark the end of any word } } private final TrieNode root; + /** + * Constructor to initialize the Trie. + * The root node is created but doesn't represent any character. + */ public TrieImp() { - root = new TrieNode(); + root = new TrieNode(); // Initialize the root node of the Trie } + /** + * Inserts a word into the Trie. + *

+ * The method traverses the Trie from the root, character by character, and adds + * nodes + * if necessary. It marks the last node of the word as an end node. + * + * @param word The word to be inserted into the Trie. + */ public void insert(String word) { TrieNode currentNode = root; for (int i = 0; i < word.length(); i++) { + // Calculate index of character ('a' -> 0, 'b' -> 1, ..., 'z' -> 25) TrieNode node = currentNode.child[word.charAt(i) - 'a']; if (node == null) { + // If the node doesn't exist, create a new one and assign it to the child array node = new TrieNode(); currentNode.child[word.charAt(i) - 'a'] = node; } - currentNode = node; + currentNode = node; // Move to the next node } - currentNode.end = true; + currentNode.end = true; // Mark the last node as the end of a word } + /** + * Searches for a word in the Trie. + *

+ * This method traverses the Trie based on the input word and checks whether + * the word exists. It returns true if the word is found and its end flag is + * true. + * + * @param word The word to search in the Trie. + * @return true if the word exists in the Trie, false otherwise. + */ public boolean search(String word) { TrieNode currentNode = root; for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); TrieNode node = currentNode.child[ch - 'a']; if (node == null) { - return false; + return false; // Word not found } currentNode = node; } - return currentNode.end; + return currentNode.end; // Return true if it's an end node, false otherwise } + /** + * Deletes a word from the Trie. + *

+ * The method traverses the Trie to find the word and marks its end flag as + * false. + * It returns true if the word was successfully deleted, false if the word + * wasn't found. + * + * @param word The word to be deleted from the Trie. + * @return true if the word was found and deleted, false if it was not found. + */ public boolean delete(String word) { TrieNode currentNode = root; for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); TrieNode node = currentNode.child[ch - 'a']; if (node == null) { - return false; + return false; // Word not found } currentNode = node; } if (currentNode.end) { + // If the word exists, mark the end flag as false (word is deleted) currentNode.end = false; return true; } - return false; + return false; // Word doesn't exist } + /** + * Helper method to print a string to the console. + * + * @param print The string to be printed. + */ public static void sop(String print) { System.out.println(print); } /** - * Regex to check if word contains only a-z character + * Validates if a given word contains only lowercase alphabetic characters + * (a-z). + *

+ * The method uses a regular expression to check if the word matches the pattern + * of only lowercase letters. + * + * @param word The word to be validated. + * @return true if the word is valid (only a-z), false otherwise. */ public static boolean isValid(String word) { - return word.matches("^[a-z]+$"); + return word.matches("^[a-z]+$"); // Regex for lowercase letters only } + /** + * Main method to demonstrate Trie operations using user input. + *

+ * The user can choose between inserting a word, searching for a word, + * deleting a word, or quitting the program. It uses a loop to continuously + * ask for user input until the program is quit. + * + * @param args Command-line arguments (not used in this program). + */ public static void main(String[] args) { TrieImp obj = new TrieImp(); String word; - @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); + @SuppressWarnings("resource") + Scanner scan = new Scanner(System.in); + sop("string should contain only a-z character for all operation"); + + // Loop indefinitely until the user decides to quit while (true) { sop("1. Insert\n2. Search\n3. Delete\n4. Quit"); try { int t = scan.nextInt(); switch (t) { - case 1: - word = scan.next(); - if (isValid(word)) { - obj.insert(word); - } else { - sop("Invalid string: allowed only a-z"); - } - break; - case 2: - word = scan.next(); - boolean resS = false; - if (isValid(word)) { - resS = obj.search(word); - } else { - sop("Invalid string: allowed only a-z"); - } - if (resS) { - sop("word found"); - } else { - sop("word not found"); - } - break; - case 3: - word = scan.next(); - boolean resD = false; - if (isValid(word)) { - resD = obj.delete(word); - } else { - sop("Invalid string: allowed only a-z"); - } - if (resD) { - sop("word got deleted successfully"); - } else { - sop("word not found"); - } - break; - case 4: - sop("Quit successfully"); - System.exit(1); - break; - default: - sop("Input int from 1-4"); - break; + case 1: + // Insert a word into the Trie + word = scan.next(); + if (isValid(word)) { + obj.insert(word); + sop("Word inserted successfully"); + } else { + sop("Invalid string: allowed only a-z"); + } + break; + case 2: + // Search for a word in the Trie + word = scan.next(); + boolean resS = false; + if (isValid(word)) { + resS = obj.search(word); + } else { + sop("Invalid string: allowed only a-z"); + } + sop(resS ? "Word found" : "Word not found"); + break; + case 3: + // Delete a word from the Trie + word = scan.next(); + boolean resD = false; + if (isValid(word)) { + resD = obj.delete(word); + } else { + sop("Invalid string: allowed only a-z"); + } + sop(resD ? "Word deleted successfully" : "Word not found"); + break; + case 4: + // Quit the program + sop("Quit successfully"); + System.exit(1); + break; + default: + sop("Input int from 1-4"); + break; } } catch (Exception e) { + // Handle bad input String badInput = scan.next(); sop("This is bad input: " + badInput); } From 8f7881bd0e600ff9627729a7bcc54d0479c3a092 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Wed, 2 Oct 2024 20:14:51 +0530 Subject: [PATCH 2/8] Fix clang errors --- .../datastructures/trees/TrieImp.java | 95 +++++++++---------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java index 61a73598383b..a83e1e323a70 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java @@ -57,7 +57,7 @@ public TrieImp() { * The method traverses the Trie from the root, character by character, and adds * nodes * if necessary. It marks the last node of the word as an end node. - * + * * @param word The word to be inserted into the Trie. */ public void insert(String word) { @@ -81,7 +81,7 @@ public void insert(String word) { * This method traverses the Trie based on the input word and checks whether * the word exists. It returns true if the word is found and its end flag is * true. - * + * * @param word The word to search in the Trie. * @return true if the word exists in the Trie, false otherwise. */ @@ -105,7 +105,7 @@ public boolean search(String word) { * false. * It returns true if the word was successfully deleted, false if the word * wasn't found. - * + * * @param word The word to be deleted from the Trie. * @return true if the word was found and deleted, false if it was not found. */ @@ -129,7 +129,7 @@ public boolean delete(String word) { /** * Helper method to print a string to the console. - * + * * @param print The string to be printed. */ public static void sop(String print) { @@ -142,7 +142,7 @@ public static void sop(String print) { *

* The method uses a regular expression to check if the word matches the pattern * of only lowercase letters. - * + * * @param word The word to be validated. * @return true if the word is valid (only a-z), false otherwise. */ @@ -156,14 +156,13 @@ public static boolean isValid(String word) { * The user can choose between inserting a word, searching for a word, * deleting a word, or quitting the program. It uses a loop to continuously * ask for user input until the program is quit. - * + * * @param args Command-line arguments (not used in this program). */ public static void main(String[] args) { TrieImp obj = new TrieImp(); String word; - @SuppressWarnings("resource") - Scanner scan = new Scanner(System.in); + @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); sop("string should contain only a-z character for all operation"); @@ -173,46 +172,46 @@ public static void main(String[] args) { try { int t = scan.nextInt(); switch (t) { - case 1: - // Insert a word into the Trie - word = scan.next(); - if (isValid(word)) { - obj.insert(word); - sop("Word inserted successfully"); - } else { - sop("Invalid string: allowed only a-z"); - } - break; - case 2: - // Search for a word in the Trie - word = scan.next(); - boolean resS = false; - if (isValid(word)) { - resS = obj.search(word); - } else { - sop("Invalid string: allowed only a-z"); - } - sop(resS ? "Word found" : "Word not found"); - break; - case 3: - // Delete a word from the Trie - word = scan.next(); - boolean resD = false; - if (isValid(word)) { - resD = obj.delete(word); - } else { - sop("Invalid string: allowed only a-z"); - } - sop(resD ? "Word deleted successfully" : "Word not found"); - break; - case 4: - // Quit the program - sop("Quit successfully"); - System.exit(1); - break; - default: - sop("Input int from 1-4"); - break; + case 1: + // Insert a word into the Trie + word = scan.next(); + if (isValid(word)) { + obj.insert(word); + sop("Word inserted successfully"); + } else { + sop("Invalid string: allowed only a-z"); + } + break; + case 2: + // Search for a word in the Trie + word = scan.next(); + boolean resS = false; + if (isValid(word)) { + resS = obj.search(word); + } else { + sop("Invalid string: allowed only a-z"); + } + sop(resS ? "Word found" : "Word not found"); + break; + case 3: + // Delete a word from the Trie + word = scan.next(); + boolean resD = false; + if (isValid(word)) { + resD = obj.delete(word); + } else { + sop("Invalid string: allowed only a-z"); + } + sop(resD ? "Word deleted successfully" : "Word not found"); + break; + case 4: + // Quit the program + sop("Quit successfully"); + System.exit(1); + break; + default: + sop("Input int from 1-4"); + break; } } catch (Exception e) { // Handle bad input From 02949105ff15413ceebe4d201f351e6099744293 Mon Sep 17 00:00:00 2001 From: Hardvan Date: Fri, 4 Oct 2024 14:26:29 +0000 Subject: [PATCH 3/8] Update directory --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 24cd22f67d07..af5905d00747 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -238,6 +238,7 @@ * [KnapsackMemoization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/KnapsackMemoization.java) * [LevenshteinDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LevenshteinDistance.java) * [LongestAlternatingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java) + * [LongestArithmeticSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequence.java) * [LongestCommonSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestCommonSubsequence.java) * [LongestIncreasingSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequence.java) * [LongestPalindromicSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubsequence.java) @@ -733,6 +734,7 @@ * [KnapsackTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/KnapsackTest.java) * [LevenshteinDistanceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LevenshteinDistanceTests.java) * [LongestAlternatingSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequenceTest.java) + * [LongestArithmeticSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestArithmeticSubsequenceTest.java) * [LongestIncreasingSubsequenceTests](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestIncreasingSubsequenceTests.java) * [LongestPalindromicSubstringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestPalindromicSubstringTest.java) * [LongestValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/dynamicprogramming/LongestValidParenthesesTest.java) From 63ae51179fbfc1fce1efd7dc2f9a027b9a74fe86 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Fri, 4 Oct 2024 20:00:23 +0530 Subject: [PATCH 4/8] Remove duplicate comments, add junit tests --- .../datastructures/trees/TrieImp.java | 102 +++--------------- .../datastructures/trees/TrieImpTest.java | 76 +++++++++++++ 2 files changed, 88 insertions(+), 90 deletions(-) create mode 100644 src/test/java/com/thealgorithms/datastructures/trees/TrieImpTest.java diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java index a83e1e323a70..48ad187b0bca 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java @@ -25,19 +25,16 @@ public class TrieImp { */ public class TrieNode { - // Array to store references to child nodes, one for each letter of the alphabet - // (a-z) TrieNode[] child; - - boolean end; // Flag to indicate if this node marks the end of a valid word + boolean end; /** * Constructor to initialize a TrieNode with an empty child array and set end to * false. */ public TrieNode() { - child = new TrieNode[26]; // Initialize child array with 26 slots (for each letter a-z) - end = false; // By default, this node doesn't mark the end of any word + child = new TrieNode[26]; + end = false; } } @@ -48,31 +45,28 @@ public TrieNode() { * The root node is created but doesn't represent any character. */ public TrieImp() { - root = new TrieNode(); // Initialize the root node of the Trie + root = new TrieNode(); } /** * Inserts a word into the Trie. *

* The method traverses the Trie from the root, character by character, and adds - * nodes - * if necessary. It marks the last node of the word as an end node. + * nodes if necessary. It marks the last node of the word as an end node. * * @param word The word to be inserted into the Trie. */ public void insert(String word) { TrieNode currentNode = root; for (int i = 0; i < word.length(); i++) { - // Calculate index of character ('a' -> 0, 'b' -> 1, ..., 'z' -> 25) TrieNode node = currentNode.child[word.charAt(i) - 'a']; if (node == null) { - // If the node doesn't exist, create a new one and assign it to the child array node = new TrieNode(); currentNode.child[word.charAt(i) - 'a'] = node; } - currentNode = node; // Move to the next node + currentNode = node; } - currentNode.end = true; // Mark the last node as the end of a word + currentNode.end = true; } /** @@ -91,11 +85,11 @@ public boolean search(String word) { char ch = word.charAt(i); TrieNode node = currentNode.child[ch - 'a']; if (node == null) { - return false; // Word not found + return false; } currentNode = node; } - return currentNode.end; // Return true if it's an end node, false otherwise + return currentNode.end; } /** @@ -115,16 +109,15 @@ public boolean delete(String word) { char ch = word.charAt(i); TrieNode node = currentNode.child[ch - 'a']; if (node == null) { - return false; // Word not found + return false; } currentNode = node; } if (currentNode.end) { - // If the word exists, mark the end flag as false (word is deleted) currentNode.end = false; return true; } - return false; // Word doesn't exist + return false; } /** @@ -147,77 +140,6 @@ public static void sop(String print) { * @return true if the word is valid (only a-z), false otherwise. */ public static boolean isValid(String word) { - return word.matches("^[a-z]+$"); // Regex for lowercase letters only - } - - /** - * Main method to demonstrate Trie operations using user input. - *

- * The user can choose between inserting a word, searching for a word, - * deleting a word, or quitting the program. It uses a loop to continuously - * ask for user input until the program is quit. - * - * @param args Command-line arguments (not used in this program). - */ - public static void main(String[] args) { - TrieImp obj = new TrieImp(); - String word; - @SuppressWarnings("resource") Scanner scan = new Scanner(System.in); - - sop("string should contain only a-z character for all operation"); - - // Loop indefinitely until the user decides to quit - while (true) { - sop("1. Insert\n2. Search\n3. Delete\n4. Quit"); - try { - int t = scan.nextInt(); - switch (t) { - case 1: - // Insert a word into the Trie - word = scan.next(); - if (isValid(word)) { - obj.insert(word); - sop("Word inserted successfully"); - } else { - sop("Invalid string: allowed only a-z"); - } - break; - case 2: - // Search for a word in the Trie - word = scan.next(); - boolean resS = false; - if (isValid(word)) { - resS = obj.search(word); - } else { - sop("Invalid string: allowed only a-z"); - } - sop(resS ? "Word found" : "Word not found"); - break; - case 3: - // Delete a word from the Trie - word = scan.next(); - boolean resD = false; - if (isValid(word)) { - resD = obj.delete(word); - } else { - sop("Invalid string: allowed only a-z"); - } - sop(resD ? "Word deleted successfully" : "Word not found"); - break; - case 4: - // Quit the program - sop("Quit successfully"); - System.exit(1); - break; - default: - sop("Input int from 1-4"); - break; - } - } catch (Exception e) { - // Handle bad input - String badInput = scan.next(); - sop("This is bad input: " + badInput); - } - } + return word.matches("^[a-z]+$"); } } diff --git a/src/test/java/com/thealgorithms/datastructures/trees/TrieImpTest.java b/src/test/java/com/thealgorithms/datastructures/trees/TrieImpTest.java new file mode 100644 index 000000000000..600fdef0a718 --- /dev/null +++ b/src/test/java/com/thealgorithms/datastructures/trees/TrieImpTest.java @@ -0,0 +1,76 @@ +package com.thealgorithms.datastructures.trees; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class TrieImpTest { + private TrieImp trie; + + @BeforeEach + public void setUp() { + trie = new TrieImp(); + } + + @Test + public void testInsertAndSearchBasic() { + String word = "hello"; + trie.insert(word); + assertTrue(trie.search(word), "Search should return true for an inserted word."); + } + + @Test + public void testSearchNonExistentWord() { + String word = "world"; + assertFalse(trie.search(word), "Search should return false for a non-existent word."); + } + + @Test + public void testInsertAndSearchMultipleWords() { + String word1 = "cat"; + String word2 = "car"; + trie.insert(word1); + trie.insert(word2); + + assertTrue(trie.search(word1), "Search should return true for an inserted word."); + assertTrue(trie.search(word2), "Search should return true for another inserted word."); + assertFalse(trie.search("dog"), "Search should return false for a word not in the Trie."); + } + + @Test + public void testDeleteExistingWord() { + String word = "remove"; + trie.insert(word); + assertTrue(trie.delete(word), "Delete should return true for an existing word."); + assertFalse(trie.search(word), "Search should return false after deletion."); + } + + @Test + public void testDeleteNonExistentWord() { + String word = "nonexistent"; + assertFalse(trie.delete(word), "Delete should return false for a non-existent word."); + } + + @Test + public void testInsertAndSearchPrefix() { + String prefix = "pre"; + String word = "prefix"; + trie.insert(prefix); + trie.insert(word); + + assertTrue(trie.search(prefix), "Search should return true for an inserted prefix."); + assertTrue(trie.search(word), "Search should return true for a word with the prefix."); + assertFalse(trie.search("pref"), "Search should return false for a prefix that is not a full word."); + } + + @Test + public void testIsValidWord() { + assertTrue(TrieImp.isValid("validword"), "Word should be valid (only lowercase letters)."); + assertFalse(TrieImp.isValid("InvalidWord"), "Word should be invalid (contains uppercase letters)."); + assertFalse(TrieImp.isValid("123abc"), "Word should be invalid (contains numbers)."); + assertFalse(TrieImp.isValid("hello!"), "Word should be invalid (contains special characters)."); + assertFalse(TrieImp.isValid(""), "Empty string should be invalid."); + } +} From 1e2cb8f92bf95107a80af85f8fb2c1d81bea8b4d Mon Sep 17 00:00:00 2001 From: Hardvan Date: Fri, 4 Oct 2024 14:30:41 +0000 Subject: [PATCH 5/8] Update directory --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index af5905d00747..3d56fa8cd321 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -719,6 +719,7 @@ * [SameTreesCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/SameTreesCheckTest.java) * [SplayTreeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/SplayTreeTest.java) * [TreeTestUtils](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/TreeTestUtils.java) + * [TrieImpTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/TrieImpTest.java) * [VerticalOrderTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/VerticalOrderTraversalTest.java) * [ZigzagTraversalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/trees/ZigzagTraversalTest.java) * divideandconquer From c8bdf3cb39f58557b2de2a54d45a3e65b1dbad21 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Fri, 4 Oct 2024 20:01:45 +0530 Subject: [PATCH 6/8] Fix comment --- .../java/com/thealgorithms/datastructures/trees/TrieImp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java index 48ad187b0bca..cb5503d180ad 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java @@ -29,8 +29,8 @@ public class TrieNode { boolean end; /** - * Constructor to initialize a TrieNode with an empty child array and set end to - * false. + * Constructor to initialize a TrieNode with an empty child array + * and set end to false. */ public TrieNode() { child = new TrieNode[26]; From b77b258cbb5621c791f923f5ebaf22af27c93950 Mon Sep 17 00:00:00 2001 From: Hardik Pawar Date: Fri, 4 Oct 2024 20:10:13 +0530 Subject: [PATCH 7/8] Remove unused import --- .../java/com/thealgorithms/datastructures/trees/TrieImp.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java index cb5503d180ad..a43a454146cb 100644 --- a/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java +++ b/src/main/java/com/thealgorithms/datastructures/trees/TrieImp.java @@ -1,7 +1,5 @@ package com.thealgorithms.datastructures.trees; -import java.util.Scanner; - /** * Trie Data structure implementation without any libraries. *

From bc20bc3c9a2c849b2e200cc8886f70e9106a623b Mon Sep 17 00:00:00 2001 From: siriak Date: Sat, 5 Oct 2024 08:40:43 +0000 Subject: [PATCH 8/8] Update directory --- DIRECTORY.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 50419f638127..fbd3b01c6321 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -22,7 +22,7 @@ * [WordSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/backtracking/WordSearch.java) * bitmanipulation * [BitSwap](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/BitSwap.java) - * [CountSetBits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountSetBits.java) + * [CountSetBits](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/CountSetBits.java) * [HighestSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/HighestSetBit.java) * [IndexOfRightMostSetBit](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBit.java) * [IsEven](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/bitmanipulation/IsEven.java) @@ -69,7 +69,7 @@ * [HexaDecimalToBinary](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java) * [HexaDecimalToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexaDecimalToDecimal.java) * [HexToOct](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/HexToOct.java) - * [IntegerToEnglish] (https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java) + * [IntegerToEnglish](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/IntegerToEnglish.java) * [IntegerToRoman](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/IntegerToRoman.java) * [OctalToBinary](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/OctalToBinary.java) * [OctalToDecimal](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/OctalToDecimal.java) @@ -410,7 +410,7 @@ * [WordBoggle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/WordBoggle.java) * others * [ArrayLeftRotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ArrayLeftRotation.java) - * [ArrayRightRotation](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayRightRotation.java) + * [ArrayRightRotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ArrayRightRotation.java) * [BankersAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BankersAlgorithm.java) * [BFPRT](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BFPRT.java) * [BoyerMoore](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/BoyerMoore.java) @@ -559,8 +559,8 @@ * [CharactersSame](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CharactersSame.java) * [CheckAnagrams](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CheckAnagrams.java) * [CheckVowels](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CheckVowels.java) - * [CountChar](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountChar.java) - * [CountWords](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/CountWords.java) + * [CountChar](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CountChar.java) + * [CountWords](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/CountWords.java) * [HammingDistance](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/HammingDistance.java) * [HorspoolSearch](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/HorspoolSearch.java) * [Isomorphic](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Isomorphic.java) @@ -575,13 +575,13 @@ * [Pangram](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Pangram.java) * [PermuteString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/PermuteString.java) * [RabinKarp](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/RabinKarp.java) - * [ReturnSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ReturnSubsequence.java) + * [ReturnSubsequence](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReturnSubsequence.java) * [ReverseString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseString.java) * [ReverseStringRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java) * [ReverseWordsInString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ReverseWordsInString.java) * [Rotation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Rotation.java) * [StringCompression](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/StringCompression.java) - * [StringMatchFiniteAutomata](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/StringMatchFiniteAutomata.java) + * [StringMatchFiniteAutomata](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/StringMatchFiniteAutomata.java) * [Upper](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/Upper.java) * [ValidParentheses](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/ValidParentheses.java) * [WordLadder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/strings/WordLadder.java) @@ -606,7 +606,7 @@ * [WordSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/backtracking/WordSearchTest.java) * bitmanipulation * [BitSwapTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/BitSwapTest.java) - * [CountSetBitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountSetBitsTest.java) + * [CountSetBitsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/CountSetBitsTest.java) * [HighestSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/HighestSetBitTest.java) * [IndexOfRightMostSetBitTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IndexOfRightMostSetBitTest.java) * [IsEvenTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/bitmanipulation/IsEvenTest.java) @@ -621,6 +621,7 @@ * [BlowfishTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/BlowfishTest.java) * [CaesarTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/CaesarTest.java) * [DESTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/DESTest.java) + * [HillCipherTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/HillCipherTest.java) * [PlayfairTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/PlayfairTest.java) * [PolybiusTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/PolybiusTest.java) * [RSATest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/RSATest.java) @@ -639,6 +640,7 @@ * [HexaDecimalToBinaryTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexaDecimalToBinaryTest.java) * [HexaDecimalToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexaDecimalToDecimalTest.java) * [HexToOctTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/HexToOctTest.java) + * [IntegerToEnglishTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/IntegerToEnglishTest.java) * [IntegerToRomanTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/IntegerToRomanTest.java) * [OctalToBinaryTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/OctalToBinaryTest.java) * [OctalToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/OctalToDecimalTest.java) @@ -992,8 +994,8 @@ * [CharacterSameTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CharacterSameTest.java) * [CheckAnagramsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CheckAnagramsTest.java) * [CheckVowelsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CheckVowelsTest.java) - * [CountCharTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountCharTest.java) - * [CountWordsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/CountWordsTest.java) + * [CountCharTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CountCharTest.java) + * [CountWordsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/CountWordsTest.java) * [HammingDistanceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/HammingDistanceTest.java) * [HorspoolSearchTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/HorspoolSearchTest.java) * [IsomorphicTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/IsomorphicTest.java) @@ -1006,13 +1008,13 @@ * [PalindromeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PalindromeTest.java) * [PangramTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PangramTest.java) * [PermuteStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PermuteStringTest.java) - * [ReturnSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReturnSubsequenceTest.java) + * [ReturnSubsequenceTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReturnSubsequenceTest.java) * [ReverseStringRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java) * [ReverseStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseStringTest.java) * [ReverseWordsInStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ReverseWordsInStringTest.java) * [RotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/RotationTest.java) * [StringCompressionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/StringCompressionTest.java) - * [StringMatchFiniteAutomataTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/StringMatchFiniteAutomataTest.java) + * [StringMatchFiniteAutomataTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/StringMatchFiniteAutomataTest.java) * [UpperTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/UpperTest.java) * [ValidParenthesesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/ValidParenthesesTest.java) * [WordLadderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/WordLadderTest.java)