Skip to content

Commit f37be2a

Browse files
authored
Improve documentation in PATRICIA_Trie.java
1 parent 89035c3 commit f37be2a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/com/thealgorithms/datastructures/trees/PATRICIA_Trie.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,33 @@ public final class PatriciaTrie {
2525
/**
2626
* Represents a node in the Patricia Trie.
2727
* All nodes are internal nodes that store the key data at the point of creation,
28-
* and their `bitNumber` indicates the bit position to check when traversing.
28+
* and their {@code bitNumber} indicates the bit position to check when traversing.
2929
*/
3030
private static class PatriciaTrieNode {
3131
/**
32-
* The bit index (1-indexed from MSB) to check for branching at this node.
33-
* The index must be greater than that of the parent node.
32+
* The bit index (1-indexed from MSB, 1 to 32) to check for branching at this node.
33+
* The index must be greater than that of the parent node. A value of 0 is used for the root.
3434
*/
3535
int bitNumber;
3636
/**
37-
* The integer key stored at this node. This is the **data** that was inserted
38-
* to create this node and acts as a placeholder or final result during search.
37+
* The integer key stored at this node. This key is used for the final comparison
38+
* after traversing the trie structure to determine if the key exists.
3939
*/
4040
int key;
4141
/**
42-
* Pointer to the next node if the current bit is 0.
42+
* Pointer to the next node if the current bit being examined is 0.
4343
*/
4444
PatriciaTrieNode leftChild;
4545
/**
46-
* Pointer to the next node if the current bit is 1.
46+
* Pointer to the next node if the current bit being examined is 1.
4747
*/
4848
PatriciaTrieNode rightChild;
4949

50+
/**
51+
* Constructs a new PatriciaTrieNode.
52+
* @param bitNumber The bit index for comparison at this node.
53+
* @param key The integer key associated with this node.
54+
*/
5055
PatriciaTrieNode(int bitNumber, int key) {
5156
this.bitNumber = bitNumber;
5257
this.key = key;
@@ -170,6 +175,8 @@ private PatriciaTrieNode insert(PatriciaTrieNode t, int element) {
170175

171176
// 3. Check for Duplicates
172177
if (element == lastNode.key) {
178+
// Note: Printing to stdout within a core algorithm method is generally discouraged
179+
// but is kept here for informational context during the insertion process.
173180
System.out.println("Key " + element + " already present.");
174181
return t;
175182
}

0 commit comments

Comments
 (0)