* Added surface area of a cuboid
Added surface area of a cuboid according to the formula:
S = 2 * (ab + ac + bc)
* Removed extra white space
* Added test for cuboid surface area
* fixed syntax error
* Removed extra space
* Added tests for cuboid surface area that should fail
I have added tests for cuboid surface area where one of the parameters is invalid. These should fail.
* Added volume of a torus
Added function calculation the volume of a torus according to the formula:
V = 2 * pi^2 * R * r^2
where R is the major radius and r is the minor radius of the torus.
* Added test for torus volume
* Added volume of a pyramid frustum
Added a function calculating volume of a pyramid frustum, V=(S1+S2+sqrt(S1*S2))*h/3
* compiler error fixed
* Added pyramid frustum test case
* extra space removed
* Add Longest Repeated Substring algorithm
Implement LongestRepeatedSubstring in the strings package using the
existing SuffixArray and Kasai's algorithm for LCP array construction.
Includes parameterized unit tests covering typical and edge cases.
* style: reformat test file per clang-format and add coverage test
---------
Co-authored-by: Çağlar Eker <eker.caglar@hepsiburada.com>
* add Subarray Sum Equals K using prefix sum
* Add RangeSumQuery algorithm in prefix folder
* chore: apply clang-format to RangeSumQueryTest file
* Add import statement for JUnit test class
---------
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
* Add Tower of Hanoi recursive algorithm with tests
* Fix SpotBugs issues and format TowerOfHanoi tests
* Enhance existing TowerOfHanoi and remove duplicate recursion version
* Fix clang-format issue
---------
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
refactor: remove duplicate algorithm implementations
Removed the following duplicate implementations:
- searches/PerfectBinarySearch.java (duplicate of IterativeBinarySearch)
- searches/SortOrderAgnosticBinarySearch.java (duplicate of OrderAgnosticBinarySearch)
- strings/LongestPalindromicSubstring.java (duplicate of dynamicprogramming version)
- strings/ValidParentheses.java (duplicate of stacks version)
- others/cn/HammingDistance.java (duplicate - strings version handles text)
- others/NewManShanksPrimeTest.java (orphan test in wrong package)
Updated DIRECTORY.md to reflect the changes.
Fixes#7253
Co-authored-by: Ahmed Allam <60698204+AllamF5J@users.noreply.github.com>
* feat: implement Smooth Sort algorithm with detailed JavaDoc and test class
* style: format LEONARDO array for improved readability with clang-format
* feat: add MiddleOfLinkedList class and corresponding test cases
* docs: update documentation for MiddleOfLinkedList class
* test: refactor MiddleOfLinkedListTest to improve readability and assertions
* test: refactor MiddleOfLinkedListTest for improved null safety and readability
---------
Co-authored-by: Ahmed Allam <60698204+AllamF5J@users.noreply.github.com>
* feat: implement Smooth Sort algorithm with detailed JavaDoc and test class
* style: format LEONARDO array for improved readability with clang-format
* feat(sorts): add TournamentSort (winner-tree)
* test: add unit test for null array handling in TournamentSort
* feat(search): add rotated binary search
* test: add unit test for handling middle element in right sorted half of rotated array
---------
Co-authored-by: Ahmed Allam <60698204+AllamF5J@users.noreply.github.com>
* feat: implement Smooth Sort algorithm with detailed JavaDoc and test class
* style: format LEONARDO array for improved readability with clang-format
* feat(sorts): add TournamentSort (winner-tree)
* test: add unit test for null array handling in TournamentSort
---------
Co-authored-by: Ahmed Allam <60698204+AllamF5J@users.noreply.github.com>
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
Co-authored-by: Oleksandr Klymenko <19151554+alxkm@users.noreply.github.com>
* feat: implement Smooth Sort algorithm with detailed JavaDoc and test class
* style: format LEONARDO array for improved readability with clang-format
---------
Co-authored-by: Ahmed Allam <60698204+AllamF5J@users.noreply.github.com>
* Add StochasticMatrix utility class
This class provides methods to check if a matrix is row-stochastic or column-stochastic, ensuring all elements are non-negative and the sums of rows or columns equal 1.
* Change package from maths to matrix
Updated package declaration for StochasticMatrix class.
* Change package declaration in StochasticMatrixTest
* Delete src/test/java/com/thealgorithms/StochasticMatrixTest.java
* Refactor matrix initialization for test cases
* Fix formatting of matrix initialization in tests
* Remove unnecessary newline in StochasticMatrix
* Add import statement for JUnit in StochasticMatrixTest
* Add additional assertions to StochasticMatrixTest
* Clean up import statements in StochasticMatrixTest
Removed unused import statements for cleaner code.
* Reorder import statements in StochasticMatrixTest
* Remove unused import assertThrows from StochasticMatrixTest
Removed unused import for assertThrows.
* Implement LengthOfLastWord algorithm in strings package
* Add JUnit tests for LengthOfLastWord algorithm
* style: fix import order and spacing for clang-format
* Add additional edge cases to GCD unit tests
* Rename GCD test methods and add descriptive names
* Fix formatting in GCD tests
---------
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
* [FEAT] Add Thin Lens formula for ray optics
* [CI] Re-run clang-format checks
* [CI] Re-run checks after rebase
* [STYLE] Apply clang-format to ThinLensTest
---------
Co-authored-by: Koushik Sai <nyamathabadkoushik@gmail.com>
* Add unit tests for graph algorithms (BFS, DFS, Dijkstra, Bellman-Ford) #7133
- Created BellmanFordTest.java with 10 test methods covering various graph scenarios
- Created ConnectedComponentTest.java with 15 test methods for DFS-based component counting
- Enhanced MatrixGraphsTest.java with additional BFS/DFS test cases
- Enhanced DijkstraAlgorithmTest.java with comprehensive shortest path tests
Fixes#7133
* fix: format files using clang
* fix: removing my changes on pull_request_template
---------
Co-authored-by: prashantdubeypng <vinoddubey6059@gmail.com>
* Add Snell's Law implementation for refraction angle
* Add tests for Snell's Law calculations
* Update documentation with reference link to Snell's Law
Added a reference link to Snell's Law in the documentation.
* Prevent instantiation of SnellLaw class
Make SnellLaw class non-instantiable by adding a private constructor.
* Rename SnellsLawTest to SnellLawTest
* Refactor SnellLawTest for clarity and accuracy
* Rename SnellsLaw.java to SnellLaw.java
* Refactor SnellLawTest with additional assertions
* Refactor SnellLaw class constructor and error handling
Refactor SnellLaw constructor and error message formatting.
* Fix missing newline at end of SnellLawTest.java
Ensure that the SnellLawTest class has a newline at the end of the file.
* Simplify assertions in SnellLawTest
* Simplify exception throwing for total internal reflection
* Add Gomory–Hu Tree (all-pairs min-cuts via n1 max-flows)
* Stabilize Monte Carlo integration with antithetic variates to reduce variance
* Fix Checkstyle in GomoryHuTreeTest: remove inner assignments, add braces, split declarations
* SpotBugs: use RandomGenerator interface in test helper
---------
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
* feat: Add Centroid Decomposition for trees (#7054)
- Implement CentroidDecomposition with O(N log N) construction
- Add CentroidTree class with parent tracking and query methods
- Include buildFromEdges helper for easy tree construction
- Add comprehensive test suite with 20+ test cases
- Cover edge cases, validation, and various tree structures
Closes#7054
* feat: Add Centroid Decomposition for trees (#7054)
- Implement CentroidDecomposition with O(N log N) construction
- Add CentroidTree class with parent tracking and query methods
- Include buildFromEdges helper for easy tree construction
- Add comprehensive test suite with 20+ test cases
- Cover edge cases, validation, and various tree structures
Closes#7054
* fix: Remove trailing whitespace from CentroidDecompositionTest
* fix: Remove trailing whitespace and add newlines at end of files
* fix: Format code to comply with clang-format and checkstyle requirements
* style: Fix lambda formatting in test assertions
- Change single-line lambdas to multi-line format
- Align with repository code style guidelines
* style: Apply clang-format to match repository style guide
- Format code according to .clang-format configuration
- Use single-line lambdas as allowed by AllowShortLambdasOnASingleLine: All
- Apply 4-space indentation
- Ensure proper line endings