Repository: TheAlgorithms/Java
Pull request #6164 (2025-02-13 11:58:38)

Refactor existing LWWElementSet implementation
<!--
Thank you for your contribution!
In order to reduce the number of notifications sent to the maintainers, please:
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
- make sure that all of the CI checks pass,
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
-->

<!-- For completed items, change [ ] to [x] -->
Refactor of the existing LWWElementSet Implementation:

- Added generic support to allow the set to store any type of element.
- Updated Javadoc to reflect changes and improve clarity.
-  Refactored timestamp comparison to remove bias, following the recommendations outlined in [A comprehensive study of Convergent and Commutative Replicated Data Types](https://inria.hal.science/inria-00555588v1/document).
- Removed the unused `compare` method, which is no longer needed due to updated timestamp comparison logic.
- Updated existing test cases to align with changes in LWWElementSet implementation
- Improved test readability and coverage 

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6164?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) Report
Attention: Patch coverage is `93.33333%` with `1 line` in your changes missing coverage. Please review.
> Project coverage is 73.98%. Comparing base [(`3313ddc`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/3313ddc7233a3b7751cdf3ccdd0954bf27c1f865?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) to head [(`194e1a9`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/194e1a99799ffa9ebd01e0aeaa3728f99983b358?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

| [Files with missing lines](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6164?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) | Patch % | Lines |
|---|---|---|
| [...ealgorithms/datastructures/crdt/LWWElementSet.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6164?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fdatastructures%2Fcrdt%2FLWWElementSet.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9kYXRhc3RydWN0dXJlcy9jcmR0L0xXV0VsZW1lbnRTZXQuamF2YQ==) | 93.33% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6164?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff              @@
##             master    #6164      +/-   ##
============================================
+ Coverage     73.94%   73.98%   +0.03%     
+ Complexity     5161     5159       -2     
============================================
  Files           662      662              
  Lines         17695    17681      -14     
  Branches       3412     3407       -5     
============================================
- Hits          13085    13081       -4     
+ Misses         4102     4097       -5     
+ Partials        508      503       -5     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6164?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).


Patch:
diff --git a/DIRECTORY.md b/DIRECTORY.md
index 4fa1392a..6ccaf0b3 100644
--- a/DIRECTORY.md
+++ b/DIRECTORY.md
@@ -332,6 +332,7 @@
             * [MidpointEllipse](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/geometry/MidpointEllipse.java)
             * [Point](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/geometry/Point.java)
           * graph
+            * [ConstrainedShortestPath](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/graph/ConstrainedShortestPath.java)
             * [StronglyConnectedComponentOptimized](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java)
           * greedyalgorithms
             * [ActivitySelection](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/greedyalgorithms/ActivitySelection.java)
@@ -419,18 +420,13 @@
             * [LeastCommonMultiple](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java)
             * [LeonardoNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LeonardoNumber.java)
             * [LinearDiophantineEquationsSolver](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LinearDiophantineEquationsSolver.java)
-            * [LiouvilleLambdaFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LiouvilleLambdaFunction.java)
             * [LongDivision](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LongDivision.java)
             * [LucasSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LucasSeries.java)
             * [MagicSquare](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MagicSquare.java)
-            * [MatrixRank](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MatrixRank.java)
-            * [MatrixUtil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MatrixUtil.java)
             * [MaxValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MaxValue.java)
             * [Means](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Means.java)
             * [Median](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Median.java)
-            * [MillerRabinPrimalityCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MillerRabinPrimalityCheck.java)
             * [MinValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MinValue.java)
-            * [MobiusFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MobiusFunction.java)
             * [Mode](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Mode.java)
             * [NonRepeatingElement](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/NonRepeatingElement.java)
             * [NthUglyNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/NthUglyNumber.java)
@@ -447,8 +443,13 @@
             * [Pow](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Pow.java)
             * [PowerOfTwoOrNot](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PowerOfTwoOrNot.java)
             * [PowerUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PowerUsingRecursion.java)
-            * [PrimeCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PrimeCheck.java)
-            * [PrimeFactorization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PrimeFactorization.java)
+            * Prime
+              * [LiouvilleLambdaFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/LiouvilleLambdaFunction.java)
+              * [MillerRabinPrimalityCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/MillerRabinPrimalityCheck.java)
+              * [MobiusFunction](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/MobiusFunction.java)
+              * [PrimeCheck](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/PrimeCheck.java)
+              * [PrimeFactorization](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/PrimeFactorization.java)
+              * [SquareFreeInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Prime/SquareFreeInteger.java)
             * [PronicNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PronicNumber.java)
             * [PythagoreanTriple](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/PythagoreanTriple.java)
             * [QuadraticEquationSolver](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/QuadraticEquationSolver.java)
@@ -458,7 +459,6 @@
             * [SieveOfEratosthenes](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java)
             * [SimpsonIntegration](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SimpsonIntegration.java)
             * [SolovayStrassenPrimalityTest](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SolovayStrassenPrimalityTest.java)
-            * [SquareFreeInteger](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareFreeInteger.java)
             * [SquareRootWithBabylonianMethod](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareRootWithBabylonianMethod.java)
             * [SquareRootWithNewtonRaphsonMethod](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/SquareRootWithNewtonRaphsonMethod.java)
             * [StandardDeviation](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/StandardDeviation.java)
@@ -478,11 +478,14 @@
             * [InverseOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java)
             * matrixexponentiation
               * [Fibonacci](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java)
+            * [MatrixRank](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/MatrixRank.java)
             * [MatrixTranspose](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/MatrixTranspose.java)
             * [MedianOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java)
             * [MirrorOfMatrix](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java)
             * [PrintAMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java)
             * [RotateMatrixBy90Degrees](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/RotateMatrixBy90Degrees.java)
+            * utils
+              * [MatrixUtil](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/matrix/utils/MatrixUtil.java)
           * misc
             * [ColorContrastRatio](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/ColorContrastRatio.java)
             * [MapReduce](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/MapReduce.java)
@@ -499,7 +502,6 @@
             * [Sparsity](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/Sparsity.java)
             * [ThreeSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/ThreeSumProblem.java)
             * [TwoSumProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/misc/TwoSumProblem.java)
-            * [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/main/java/com/thealgorithms/others/ArrayRightRotation.java)
@@ -539,10 +541,12 @@
             * [RemoveDuplicateFromString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/RemoveDuplicateFromString.java)
             * [ReverseStackUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java)
             * [SkylineProblem](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/SkylineProblem.java)
-            * [Sudoku](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Sudoku.java)
-            * [TowerOfHanoi](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TowerOfHanoi.java)
             * [TwoPointers](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/TwoPointers.java)
             * [Verhoeff](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/Verhoeff.java)
+          * puzzlesandgames
+            * [Sudoku](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/puzzlesandgames/Sudoku.java)
+            * [TowerOfHanoi](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/puzzlesandgames/TowerOfHanoi.java)
+            * [WordBoggle](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/puzzlesandgames/WordBoggle.java)
           * recursion
             * [FibonacciSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/recursion/FibonacciSeries.java)
             * [GenerateSubsets](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/recursion/GenerateSubsets.java)
@@ -623,6 +627,7 @@
             * [CombSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CombSort.java)
             * [CountingSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CountingSort.java)
             * [CycleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CycleSort.java)
+            * [DarkSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DarkSort.java)
             * [DualPivotQuickSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DualPivotQuickSort.java)
             * [DutchNationalFlagSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/DutchNationalFlagSort.java)
             * [ExchangeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ExchangeSort.java)
@@ -1008,6 +1013,7 @@
             * [MidpointCircleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/geometry/MidpointCircleTest.java)
             * [MidpointEllipseTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/geometry/MidpointEllipseTest.java)
           * graph
+            * [ConstrainedShortestPathTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/graph/ConstrainedShortestPathTest.java)
             * [StronglyConnectedComponentOptimizedTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/graph/StronglyConnectedComponentOptimizedTest.java)
           * greedyalgorithms
             * [ActivitySelectionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java)
@@ -1087,17 +1093,12 @@
             * [KrishnamurthyNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/KrishnamurthyNumberTest.java)
             * [LeastCommonMultipleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LeastCommonMultipleTest.java)
             * [LeonardoNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LeonardoNumberTest.java)
-            * [LiouvilleLambdaFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LiouvilleLambdaFunctionTest.java)
             * [LongDivisionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LongDivisionTest.java)
             * [LucasSeriesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LucasSeriesTest.java)
-            * [MatrixRankTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MatrixRankTest.java)
-            * [MatrixUtilTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MatrixUtilTest.java)
             * [MaxValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MaxValueTest.java)
             * [MeansTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MeansTest.java)
             * [MedianTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MedianTest.java)
-            * [MillerRabinPrimalityCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MillerRabinPrimalityCheckTest.java)
             * [MinValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MinValueTest.java)
-            * [MobiusFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MobiusFunctionTest.java)
             * [ModeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/ModeTest.java)
             * [NonRepeatingElementTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NonRepeatingElementTest.java)
             * [NthUglyNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/NthUglyNumberTest.java)
@@ -1113,8 +1114,12 @@
             * [PowerOfTwoOrNotTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowerOfTwoOrNotTest.java)
             * [PowerUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowerUsingRecursionTest.java)
             * [PowTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PowTest.java)
-            * [PrimeCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PrimeCheckTest.java)
-            * [PrimeFactorizationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java)
+            * prime
+              * [LiouvilleLambdaFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/prime/LiouvilleLambdaFunctionTest.java)
+              * [MillerRabinPrimalityCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/prime/MillerRabinPrimalityCheckTest.java)
+              * [MobiusFunctionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/prime/MobiusFunctionTest.java)
+              * [PrimeCheckTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/prime/PrimeCheckTest.java)
+              * [PrimeFactorizationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/prime/PrimeFactorizationTest.java)
             * [PronicNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PronicNumberTest.java)
             * [PythagoreanTripleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/PythagoreanTripleTest.java)
             * [QuadraticEquationSolverTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/QuadraticEquationSolverTest.java)
@@ -1139,7 +1144,9 @@
             * [VolumeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/VolumeTest.java)
           * matrix
             * [InverseOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java)
+            * [MatrixRankTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/MatrixRankTest.java)
             * [MatrixTransposeTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/MatrixTransposeTest.java)
+            * [MatrixUtilTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/MatrixUtilTest.java)
             * [MedianOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/MedianOfMatrixTest.java)
             * [MirrorOfMatrixTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java)
             * [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java)
@@ -1154,7 +1161,6 @@
             * [SparsityTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/SparsityTest.java)
             * [ThreeSumProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/ThreeSumProblemTest.java)
             * [TwoSumProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/TwoSumProblemTest.java)
-            * [WordBoggleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/misc/WordBoggleTest.java)
           * others
             * [ArrayLeftRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayLeftRotationTest.java)
             * [ArrayRightRotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ArrayRightRotationTest.java)
@@ -1182,10 +1188,12 @@
             * [RemoveDuplicateFromStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/RemoveDuplicateFromStringTest.java)
             * [ReverseStackUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java)
             * [SkylineProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/SkylineProblemTest.java)
-            * [SudokuTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/SudokuTest.java)
-            * [TowerOfHanoiTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TowerOfHanoiTest.java)
             * [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java)
             * [WorstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/WorstFitCPUTest.java)
+          * puzzlesandgames
+            * [SudokuTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/puzzlesandgames/SudokuTest.java)
+            * [TowerOfHanoiTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/puzzlesandgames/TowerOfHanoiTest.java)
+            * [WordBoggleTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/puzzlesandgames/WordBoggleTest.java)
           * recursion
             * [FibonacciSeriesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/recursion/FibonacciSeriesTest.java)
             * [GenerateSubsetsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/recursion/GenerateSubsetsTest.java)
@@ -1267,6 +1275,7 @@
             * [CombSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CombSortTest.java)
             * [CountingSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CountingSortTest.java)
             * [CycleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CycleSortTest.java)
+            * [DarkSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DarkSortTest.java)
             * [DualPivotQuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DualPivotQuickSortTest.java)
             * [DutchNationalFlagSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DutchNationalFlagSortTest.java)
             * [ExchangeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/ExchangeSortTest.java)
diff --git a/src/main/java/com/thealgorithms/datastructures/crdt/LWWElementSet.java b/src/main/java/com/thealgorithms/datastructures/crdt/LWWElementSet.java
index 2c6ce8a4..d33bd3ee 100644
--- a/src/main/java/com/thealgorithms/datastructures/crdt/LWWElementSet.java
+++ b/src/main/java/com/thealgorithms/datastructures/crdt/LWWElementSet.java
@@ -1,53 +1,33 @@
 package com.thealgorithms.datastructures.crdt;
 
+import java.time.Instant;
 import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Last-Write-Wins Element Set (LWWElementSet) is a state-based CRDT (Conflict-free Replicated Data Type)
- * designed for managing sets in a distributed and concurrent environment. It supports the addition and removal
- * of elements, using timestamps to determine the order of operations. The set is split into two subsets:
- * the add set for elements to be added and the remove set for elements to be removed.
+ * Last-Write-Wins Element Set (LWWElementSet) is a state-based CRDT (Conflict-free Replicated Data
+ * Type) designed for managing sets in a distributed and concurrent environment. It supports the
+ * addition and removal of elements, using timestamps to determine the order of operations. The set
+ * is split into two subsets: the add set for elements to be added and the remove set for elements
+ * to be removed. The LWWElementSet ensures that the most recent operation (based on the timestamp)
+ * wins in the case of concurrent operations.
  *
- * @author itakurah (Niklas Hoefflin) (https://github.com/itakurah)
- * @see <a href="https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type">Conflict-free_replicated_data_type</a>
- * @see <a href="https://github.com/itakurah">itakurah (Niklas Hoefflin)</a>
+ * @param <T> The type of the elements in the LWWElementSet.
+ * @author <a href="https://github.com/itakurah">itakurah (GitHub)</a>, <a
+ * href="https://www.linkedin.com/in/niklashoefflin/">Niklas Hoefflin (LinkedIn)</a>
+ * @see <a href="https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type">Conflict free
+ * replicated data type (Wikipedia)</a>
+ * @see <a href="https://inria.hal.science/inria-00555588v1/document">A comprehensive study of
+ * Convergent and Commutative Replicated Data Types</a>
  */
-
-class Element {
-    String key;
-    int timestamp;
-    Bias bias;
+class LWWElementSet<T> {
+    final Map<T, Element<T>> addSet;
+    final Map<T, Element<T>> removeSet;
 
     /**
-     * Constructs a new Element with the specified key, timestamp and bias.
-     *
-     * @param key       The key of the element.
-     * @param timestamp The timestamp associated with the element.
-     * @param bias      The bias of the element (ADDS or REMOVALS).
-     */
-    Element(String key, int timestamp, Bias bias) {
-        this.key = key;
-        this.timestamp = timestamp;
-        this.bias = bias;
-    }
-}
-
-enum Bias {
-    /**
-     * ADDS bias for the add set.
-     * REMOVALS bias for the remove set.
-     */
-    ADDS,
-    REMOVALS
-}
-
-class LWWElementSet {
-    private final Map<String, Element> addSet;
-    private final Map<String, Element> removeSet;
-
-    /**
-     * Constructs an empty LWWElementSet.
+     * Constructs an empty LWWElementSet. This constructor initializes the addSet and removeSet as
+     * empty HashMaps. The addSet stores elements that are added, and the removeSet stores elements
+     * that are removed.
      */
     LWWElementSet() {
         this.addSet = new HashMap<>();
@@ -55,84 +35,92 @@ class LWWElementSet {
     }
 
     /**
-     * Adds an element to the addSet.
+     * Adds an element to the addSet with the current timestamp. This method stores the element in the
+     * addSet, ensuring that the element is added to the set with an associated timestamp that
+     * represents the time of the addition.
      *
-     * @param e The element to be added.
+     * @param key The key of the element to be added.
      */
-    public void add(Element e) {
-        addSet.put(e.key, e);
+    public void add(T key) {
+        addSet.put(key, new Element<>(key, Instant.now()));
     }
 
     /**
-     * Removes an element from the removeSet.
+     * Removes an element by adding it to the removeSet with the current timestamp. This method adds
+     * the element to the removeSet, marking it as removed with the current timestamp.
      *
-     * @param e The element to be removed.
+     * @param key The key of the element to be removed.
      */
-    public void remove(Element e) {
-        if (lookup(e)) {
-            removeSet.put(e.key, e);
-        }
+    public void remove(T key) {
+        removeSet.put(key, new Element<>(key, Instant.now()));
     }
 
     /**
-     * Checks if an element is in the LWWElementSet by comparing timestamps in the addSet and removeSet.
+     * Checks if an element is in the LWWElementSet. An element is considered present if it exists in
+     * the addSet and either does not exist in the removeSet, or its add timestamp is later than any
+     * corresponding remove timestamp.
      *
-     * @param e The element to be checked.
-     * @return True if the element is present, false otherwise.
+     * @param key The key of the element to be checked.
+     * @return {@code true} if the element is present in the set (i.e., its add timestamp is later
+     * than its remove timestamp, or it is not in the remove set), {@code false} otherwise (i.e.,
+     * the element has been removed or its remove timestamp is later than its add timestamp).
      */
-    public boolean lookup(Element e) {
-        Element inAddSet = addSet.get(e.key);
-        Element inRemoveSet = removeSet.get(e.key);
+    public boolean lookup(T key) {
+        Element<T> inAddSet = addSet.get(key);
+        Element<T> inRemoveSet = removeSet.get(key);
 
-        return (inAddSet != null && (inRemoveSet == null || inAddSet.timestamp > inRemoveSet.timestamp));
+        return inAddSet != null && (inRemoveSet == null || inAddSet.timestamp.isAfter(inRemoveSet.timestamp));
     }
 
     /**
-     * Compares the LWWElementSet with another LWWElementSet to check if addSet and removeSet are a subset.
+     * Merges another LWWElementSet into this set. This method takes the union of both the add-sets
+     * and remove-sets from the two sets, resolving conflicts by keeping the element with the latest
+     * timestamp. If an element appears in both the add-set and remove-set of both sets, the one with
+     * the later timestamp will be retained.
      *
-     * @param other The LWWElementSet to compare.
-     * @return True if the set is subset, false otherwise.
+     * @param other The LWWElementSet to merge with the current set.
      */
-    public boolean compare(LWWElementSet other) {
-        return other.addSet.keySet().containsAll(addSet.keySet()) && other.removeSet.keySet().containsAll(removeSet.keySet());
+    public void merge(LWWElementSet<T> other) {
+        for (Map.Entry<T, Element<T>> entry : other.addSet.entrySet()) {
+            addSet.merge(entry.getKey(), entry.getValue(), this::resolveConflict);
+        }
+        for (Map.Entry<T, Element<T>> entry : other.removeSet.entrySet()) {
+            removeSet.merge(entry.getKey(), entry.getValue(), this::resolveConflict);
+        }
     }
 
     /**
-     * Merges another LWWElementSet into this set by resolving conflicts based on timestamps.
+     * Resolves conflicts between two elements by selecting the one with the later timestamp. This
+     * method is used when merging two LWWElementSets to ensure that the most recent operation (based
+     * on timestamps) is kept.
      *
-     * @param other The LWWElementSet to merge.
+     * @param e1 The first element.
+     * @param e2 The second element.
+     * @return The element with the later timestamp.
      */
-    public void merge(LWWElementSet other) {
-        for (Element e : other.addSet.values()) {
-            if (!addSet.containsKey(e.key) || compareTimestamps(addSet.get(e.key), e)) {
-                addSet.put(e.key, e);
-            }
-        }
-
-        for (Element e : other.removeSet.values()) {
-            if (!removeSet.containsKey(e.key) || compareTimestamps(removeSet.get(e.key), e)) {
-                removeSet.put(e.key, e);
-            }
-        }
+    private Element<T> resolveConflict(Element<T> e1, Element<T> e2) {
+        return e1.timestamp.isAfter(e2.timestamp) ? e1 : e2;
     }
+}
+
+/**
+ * Represents an element in the LWWElementSet, consisting of a key and a timestamp. This class is
+ * used to store the elements in both the add and remove sets with their respective timestamps.
+ *
+ * @param <T> The type of the key associated with the element.
+ */
+class Element<T> {
+    T key;
+    Instant timestamp;
 
     /**
-     * Compares timestamps of two elements based on their bias (ADDS or REMOVALS).
+     * Constructs a new Element with the specified key and timestamp.
      *
-     * @param e     The first element.
-     * @param other The second element.
-     * @return True if the first element's timestamp is greater or the bias is ADDS and timestamps are equal.
+     * @param key       The key of the element.
+     * @param timestamp The timestamp associated with the element.
      */
-    public boolean compareTimestamps(Element e, Element other) {
-        if (e.bias != other.bias) {
-            throw new IllegalArgumentException("Invalid bias value");
-        }
-        Bias bias = e.bias;
-        int timestampComparison = Integer.compare(e.timestamp, other.timestamp);
-
-        if (timestampComparison == 0) {
-            return bias != Bias.ADDS;
-        }
-        return timestampComparison < 0;
+    Element(T key, Instant timestamp) {
+        this.key = key;
+        this.timestamp = timestamp;
     }
 }


Test patch:
diff --git a/src/test/java/com/thealgorithms/datastructures/crdt/LWWElementSetTest.java b/src/test/java/com/thealgorithms/datastructures/crdt/LWWElementSetTest.java
index 36593d66..0356949a 100644
--- a/src/test/java/com/thealgorithms/datastructures/crdt/LWWElementSetTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/crdt/LWWElementSetTest.java
@@ -3,106 +3,96 @@ package com.thealgorithms.datastructures.crdt;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.junit.jupiter.api.BeforeEach;
+import java.time.Instant;
 import org.junit.jupiter.api.Test;
 
 class LWWElementSetTest {
 
-    private LWWElementSet set;
-    private final Bias bias = Bias.ADDS;
-
-    @BeforeEach
-    void setUp() {
-        set = new LWWElementSet();
-    }
-
     @Test
-    void testAdd() {
-        Element element = new Element("key1", 1, bias);
-        set.add(element);
-
-        assertTrue(set.lookup(element));
+    void testAddElement() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+        set.add("A");
+        assertTrue(set.lookup("A"));
     }
 
     @Test
-    void testRemove() {
-        Element element = new Element("key1", 1, bias);
-        set.add(element);
-        set.remove(element);
-
-        assertFalse(set.lookup(element));
+    void testRemoveElement() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+        set.add("A");
+        set.remove("A");
+        assertFalse(set.lookup("A"));
     }
 
     @Test
-    void testRemoveNonexistentElement() {
-        Element element = new Element("key1", 1, bias);
-        set.remove(element);
-
-        assertFalse(set.lookup(element));
+    void testLookupWithoutAdding() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+        assertFalse(set.lookup("A"));
     }
 
     @Test
-    void testLookupNonexistentElement() {
-        Element element = new Element("key1", 1, bias);
+    void testLookupLaterTimestampsFalse() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+
+        set.addSet.put("A", new Element<>("A", Instant.now()));
+        set.removeSet.put("A", new Element<>("A", Instant.now().plusSeconds(10)));
 
-        assertFalse(set.lookup(element));
+        assertFalse(set.lookup("A"));
     }
 
     @Test
-    void testCompareEqualSets() {
-        LWWElementSet otherSet = new LWWElementSet();
+    void testLookupEarlierTimestampsTrue() {
+        LWWElementSet<String> set = new LWWElementSet<>();
 
-        Element element = new Element("key1", 1, bias);
-        set.add(element);
-        otherSet.add(element);
+        set.addSet.put("A", new Element<>("A", Instant.now()));
+        set.removeSet.put("A", new Element<>("A", Instant.now().minusSeconds(10)));
 
-        assertTrue(set.compare(otherSet));
-
-        otherSet.add(new Element("key2", 2, bias));
-        assertTrue(set.compare(otherSet));
+        assertTrue(set.lookup("A"));
     }
 
     @Test
-    void testCompareDifferentSets() {
-        LWWElementSet otherSet = new LWWElementSet();
-
-        Element element1 = new Element("key1", 1, bias);
-        Element element2 = new Element("key2", 2, bias);
-
-        set.add(element1);
-        otherSet.add(element2);
-
-        assertFalse(set.compare(otherSet));
+    void testLookupWithConcurrentTimestamps() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+        Instant now = Instant.now();
+        set.addSet.put("A", new Element<>("A", now));
+        set.removeSet.put("A", new Element<>("A", now));
+        assertFalse(set.lookup("A"));
     }
 
     @Test
-    void testMerge() {
-        LWWElementSet otherSet = new LWWElementSet();
+    void testMergeTwoSets() {
+        LWWElementSet<String> set1 = new LWWElementSet<>();
+        LWWElementSet<String> set2 = new LWWElementSet<>();
 
-        Element element1 = new Element("key1", 1, bias);
-        Element element2 = new Element("key2", 2, bias);
+        set1.add("A");
+        set2.add("B");
+        set2.remove("A");
 
-        set.add(element1);
-        otherSet.add(element2);
+        set1.merge(set2);
 
-        set.merge(otherSet);
-
-        assertTrue(set.lookup(element1));
-        assertTrue(set.lookup(element2));
+        assertFalse(set1.lookup("A"));
+        assertTrue(set1.lookup("B"));
     }
 
     @Test
-    void testCompareTimestampsEqualTimestamps() {
-        LWWElementSet lwwElementSet = new LWWElementSet();
+    void testMergeWithConflictingTimestamps() {
+        LWWElementSet<String> set1 = new LWWElementSet<>();
+        LWWElementSet<String> set2 = new LWWElementSet<>();
 
-        Element e1 = new Element("key1", 10, Bias.REMOVALS);
-        Element e2 = new Element("key1", 10, Bias.REMOVALS);
+        Instant now = Instant.now();
+        set1.addSet.put("A", new Element<>("A", now.minusSeconds(10)));
+        set2.addSet.put("A", new Element<>("A", now));
 
-        assertTrue(lwwElementSet.compareTimestamps(e1, e2));
+        set1.merge(set2);
 
-        e1 = new Element("key1", 10, Bias.ADDS);
-        e2 = new Element("key1", 10, Bias.ADDS);
+        assertTrue(set1.lookup("A"));
+    }
 
-        assertFalse(lwwElementSet.compareTimestamps(e1, e2));
+    @Test
+    void testRemoveOlderThanAdd() {
+        LWWElementSet<String> set = new LWWElementSet<>();
+        Instant now = Instant.now();
+        set.addSet.put("A", new Element<>("A", now));
+        set.removeSet.put("A", new Element<>("A", now.minusSeconds(10)));
+        assertTrue(set.lookup("A"));
     }
 }