Commit Graph

1021 Commits

Author SHA1 Message Date
Saniya Mane
7d51c7f320 Add additional edge cases to GCD unit tests (#7174)
* 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>
2025-12-18 07:55:03 +00:00
Rajuri Likhitha
2911a7b52c ExtendedEuclideanAlgorithm (#7172)
* commit1

* Fix clang-format spacing in array declarations
2025-12-17 22:14:12 +01:00
NYAMATHABAD KOUSHIK SAI
4f293b33e5 [FEAT] Add Thin Lens formula for ray optics (#7170)
* [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>
2025-12-17 16:48:00 +01:00
Taranjeet Singh Kalsi
d9f2ac8340 Added program to check Lucky number (#6962)
added program for lucky number
2025-12-14 10:29:14 +00:00
Muhammad Junaid Khalid
aa91451203 feat: Binary Tree to String algorithm added (Leetcode 606) (#6727)
* feat: BinaryTreeToString.java Added with tests

* fix: javadoc added to BinaryTreeToString

* fix: link to leetcode added
2025-12-14 10:14:00 +00:00
utkarsh patel
bccaf970ba Add Z-Algorithm for Linear-Time String Pattern Matching (#7124)
* Add Z-Algorithm (string pattern matching) with tests

* Add Z-Algorithm (string pattern matching) with tests

* Add Z-Algorithm (string pattern matching) with tests

* Fix checkstyle errors for ZAlgorithm

* Fix: clang-format and checkstyle compliance for ZAlgorithm
2025-12-14 10:08:18 +00:00
Lucas Horn
4f40206684 Add unit tests for graph algorithms (#7133) (#7156)
* 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>
2025-12-10 09:04:32 +00:00
Daniel Sánchez Núñez
316def4ea6 Add Snell's Law refraction algorithm (#7150)
* 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
2025-12-07 12:18:55 +01:00
duvvuvenkataramana
8d2cdb27db feat: implement One-Time Pad cipher (#6941) (#7096)
* feat: implement One-Time Pad cipher (#6941)

* style: format OneTimePadCipher with clang-format
2025-12-01 20:17:32 +00:00
Shewale Gopal Sanjay
14c0b0844e Added threaded binary tree (#6995)
* Add One-Time Pad Cipher implementation in Java

* Add One-Time Pad Cipher implementation (fixed)

* Add ThreadedBinaryTree with in-order traversal and tests

* feat: add threaded binary tree implementation and tests

* fix: remove redundant null check for SpotBugs compliance
2025-12-01 20:13:14 +00:00
Taranjeet Singh Kalsi
ac6fef19dc Added program to check either number is Evil or Odious (#6958)
added program for evil number
2025-11-30 22:37:41 +00:00
Taranjeet Singh Kalsi
a9ba87c4b6 Added program to check Abundant number (#6961)
added program for abundant number
2025-11-28 08:51:28 +00:00
Sameer Prajapati
4c5525a2e0 feat: Added Gomory–Hu Tree (all-pairs min-cuts via n1 max-flows) (#6818)
* 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>
2025-11-28 08:47:53 +00:00
Gokul45-45
d1ea306920 feat: add Valid Parentheses algorithm using Stack (#7117)
* feat: add Valid Parentheses algorithm using Stack

* fix: add missing ValidParentheses.java implementation

* fix: remove trailing spaces and add newline at EOF

* fix: remove misplaced ValidParentheses.java from root
2025-11-27 11:29:48 +00:00
KANAKALA SAI KIRAN
fa8ea8e614 Feature/centroid decomposition (#7086)
* 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
2025-11-22 09:44:34 +00:00
shreeya-g10
3519e396af backtracking: add unique permutation algorithm with test cases (#7078)
* Add unique permutation algorithm and test cases

* Fix: add braces for checkstyle

* Apply clang-format
2025-11-19 18:20:46 +02:00
GOPISETTI NAVADEEP
9f2b675f3e feat: add Sudoku Solver using Backtracking (#7073)
* feat: add Sudoku Solver using Backtracking (issue #6929)

* refactor: remove old Sudoku class from puzzlesandgames package

* Remove old Sudoku implementation and its test class
2025-11-17 09:54:20 +01:00
SeungHyeok Yun
cff5d3662e feat: add IndexedPriorityQueue implementation and tests (#7062)
* feat: add IndexedPriorityQueue implementation and tests

* mod : clang-format

* Fix Checkstyle naming for IndexedPriorityQueue tests

* Align IndexedPriorityQueue tests with Checkstyle and clang-format
2025-11-16 19:49:30 +01:00
GOPISETTI NAVADEEP
c6880c195d feat: add Sieve of Eratosthenes algorithm (#7071)
* feat: add Sieve of Eratosthenes algorithm

- Implement Sieve of Eratosthenes for finding prime numbers up to n
- Add comprehensive unit tests with edge cases
- Include JavaDoc documentation
- Time complexity: O(n log log n)
- Space complexity: O(n)

Resolves #6939

* fix: remove trailing spaces

* fix: apply clang-format
2025-11-16 12:00:21 +00:00
GOPISETTI NAVADEEP
93811614b8 feat: add Count Set Bits algorithm (#7072)
* feat: add Count Set Bits algorithm (issue #6931)

* fix: correct CountSetBits algorithm logic

* style: apply clang-format to CountSetBits files

* fix: correct test expectations for CountSetBits

* fix: correct test expectations for CountSetBits
2025-11-16 12:54:43 +01:00
Krishna
3979e824b7 Add Power of Four Check using bit manipulation (#7065)
* Add Power of Four Check using bit manipulation

- Implements isPowerOfFour method using bit manipulation
- Checks if number is power of two and has bit at even position
- Includes comprehensive unit tests
- Fixes #6940

* Fix code formatting in PowerOfFourTest

* Move PowerOfFour classes to maths package

* Fix package declaration in PowerOfFourTest

* Fix code formatting in PowerOfFourTest

* Remove redundant import from PowerOfFourTest

* Remove unrelated file
2025-11-15 18:36:01 +01:00
Taranjeet Singh Kalsi
98eecb9f16 Added program to check Smith number (#6955)
added smith number program
2025-11-15 09:32:06 +00:00
Krishna
8a339ef2e2 Add Temperature Conversion Utility (#7066)
- Implements conversions between Celsius, Fahrenheit, and Kelvin
- Includes all 6 conversion methods
- Adds comprehensive unit tests with edge cases
- Fixes #6936
2025-11-15 10:22:36 +01:00
Priyanshu Kumar Singh
4951fb9ce2 [FEAT] Add Kinematics (SUVAT) equations (#7053)
[FEAT] Add SUVAT equation for motion

Co-authored-by: Priyanshu1303d <priyanshu130d@gmail.com>
2025-11-06 18:41:39 +01:00
Arzoo1701
d126fd59f7 Add Trapping Rainwater problem implementation (Two Pointer Approach) (#6990)
* Add Trapping Rainwater problem implementation (Two Pointer Approach)

* Add Wikipedia reference link for Trapping Rainwater problem

* fix: format TrappingRainwater.java for CI check

* fix: add package and resolve checkstyle errors for TrappingRainwater.java

* fix: declare TrappingRainwater as final to pass Checkstyle

* Add test cases for TrappingRainwater algorithm

* Add test cases for TrappingRainwater algorithm

* Move TrappingRainwater algorithm to stacks package

* Fix: Move TrappingRainwater to stacks and normalize newline in JugglerSequence

* Fix: Normalize newline in JugglerSequence to ensure test consistency

* Fix: Normalize newline in JugglerSequence and remove return statement

* Add JaCoCo plugin for code coverage reporting

* Revert pom.xml to original version from master

* Fix: Revert the pom.xml file

---------

Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
2025-11-05 18:41:08 +01:00
Avaneeshakrishna
53230842f2 add CombinationSum and test (#6725)
* add CombinationSum and test

* Format array and list literals in CombinationSumTest

* Fix sorting comparator in CombinationSumTest

* Refactor CombinationSum for better handling and clarity

Updated combinationSum method to handle null or empty candidates and improved variable naming for clarity.

* Fix sorting comparator in CombinationSumTest

* Update CombinationSumTest.java

* Fix sorting comparator for list of integers

* Fix formatting issues in CombinationSum class

* Change CombinationSum class to final

* Refactor norm method to accept Iterable instead of List

* Remove unnecessary whitespace in CombinationSumTest
2025-11-05 11:22:39 +00:00
Lê Nam Khánh
5c965eb097 chore: fix typos in src/test/java/com/thealgorithms/datastructures (#7045)
Fix typos in src/test/java/com/thealgorithms/datastructures
2025-11-05 11:09:05 +02:00
Sourav Pati
100462d8e9 Added LU Decomposition Algorithm for matrix (#6834)
* Added LU decomposition algorthm

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim

* Added LU decomposition algorthim
2025-11-03 22:29:44 +01:00
Yajunesh MR
82ff14c36e feat: Add BitRotate utility for circular bit rotations (#7011)
* feat: Add BitRotate utility for circular bit rotations

* feat: Add BitRotate utility for circular bit rotations

* feat: Add BitRotate utility for circular bit rotations

* fix: Remove trailing spaces and add newline at EOF

---------

Co-authored-by: Yajunesh M R <yajunesh@Yajuneshs-MacBook-Pro.local>
2025-11-03 22:12:24 +01:00
sharan
d717ca4fd5 feat: Add Hierholzer's Algorithm for Eulerian Circuits (#6726)
* feat: Add Hierholzer's Algorithm for Eulerian Circuits

* fix: Add more test cases to improve code coverage

* feat: Add Hierholzer's Algorithm for Eulerian Circuits

* fix: Apply clang-format after merge

* fix: Apply all formatting, style, and efficiency fixes

* docs: Apply feedback and improve Javadoc

* docs: Add Hierholzer's Algorithm to DIRECTORY.md
2025-11-02 10:36:10 +00:00
Priyanshu Kumar Singh
08374248e9 [FEAT] Add Coulomb's Law for electrostatics (#7017)
Co-authored-by: Priyanshu1303d <priyanshu130d@gmail.com>
2025-11-01 09:28:44 +00:00
sairamsharan
bb6385e756 feat: Add Stoer-Wagner Algorithm for Minimum Cut (#6752)
* feat: Add Stoer-Wagner Algorithm for Minimum Cut

* fix: Correct Stoer-Wagner implementation

* fix: Remove unused import

* fix: Apply clang-format
2025-10-29 09:08:05 +00:00
Keykyrios
68746f880f feat: Add Chebyshev Iteration algorithm (#6963)
* feat: Add Chebyshev Iteration algorithm

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* update

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java

* Update ChebyshevIteration.java

* Update ChebyshevIterationTest.java
2025-10-28 17:43:54 +02:00
Keykyrios
3c70a54355 feat: Add Neville's Algorithm (#6842)
* feat: Add Neville's algorithm for polynomial interpolation

* Update Neville.java

* style: Fix linter formatting issues.

* Handled Div by Zero Case

* Update NevilleTest.java

* Update Neville.java

* Update NevilleTest.java

* Update Neville.java
2025-10-28 10:14:59 +00:00
Taranjeet Singh Kalsi
21eff8ad09 Added binary string to decimal converter (#6915)
added binary string to decimal converter
2025-10-26 22:39:39 +02:00
Krishna
a4cf6e36f4 test: Add comprehensive tests for JugglerSequence (#6947)
* test: Add comprehensive tests for JugglerSequence

- Added tests for input values 1, 2, 3, and 9
- Tests verify correct sequence output
- Improves code coverage for maths package

* fix: Format JugglerSequenceTest
2025-10-26 09:05:55 +00:00
Indolyn Yi
2da0465fe0 feat(geometry): Add Bentley-Ottmann algorithm for line segment intersection (#6871)
* feat(geometry): add Bentley-Ottmann line segment intersection algorithm

- Implement sweep-line algorithm for finding all intersection points
- Time complexity: O((n + k) log n) where n is segments, k is intersections
- Uses event queue (PriorityQueue) and status structure (TreeSet)
- Handles vertical/horizontal segments, collinear overlaps, and touching endpoints
- Includes comprehensive Javadoc with examples and references

* test(geometry): add comprehensive tests for Bentley-Ottmann algorithm

- 19 test cases covering typical, edge, and degenerate cases
- Tests include: single/multiple intersections, parallel segments, grid patterns
- Performance test with 100 random segments
- All tests validate correctness of intersection detection

* style(geometry): fix code style

* test(geometry): Achieve 100% test coverage for BentleyOttmann

* style(geometry): fix code style again

* fix: correct import order in BentleyOttmann

* fix(geometry): Resolve SpotBugs and PMD static analysis warnings

* Reorder import statements in BentleyOttmannTest

---------

Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
2025-10-25 22:18:45 +02:00
Priyanshu Kumar Singh
252155630e [FEAT] Add general purpose Projectile Motion algorithm (Physics) (#6928)
[FEAT] Add general purpose Projectile Motion algorithm

Co-authored-by: Priyanshu1303d <priyanshu130d@gmail.com>
Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
2025-10-25 22:12:45 +02:00
Priyanshu Kumar Singh
e21aee814c [FEAT] Add Newton's Law of Gravitation algorithm (#6855)
Co-authored-by: Priyanshu1303d <priyanshu130d@gmail.com>
2025-10-25 17:18:15 +02:00
Indolyn Yi
ab65ac6485 feat(compression): Add Burrows-Wheeler Transform (BWT) and Move-to-Front (MTF) (#6926)
* feat(compression): Add Burrows-Wheeler Transform (BWT) and Move-to-Front (MTF)

* Resolve SpotBugs

* fix code style
2025-10-25 11:29:45 +02:00
Indole Yi
48ba1ae466 feat(compression): Add LZ77 and LZ78 algorithms (#6910)
* feat(compression): Add LZ77 and LZ78 algorithms

* Resolve Spotbugs warning in LZ78 by using Trie structure

* fix code style
2025-10-23 18:16:46 +02:00
Hardik Pawar
f66da5e5ee refactor: Enhance docs, add tests in PrintMatrixInSpiralOrder (#6636)
* refactor: Enhance docs, add tests in `PrintMatrixInSpiralOrder`

* Fix error in BloomFilter

* Fix

* Fix

* Fix
2025-10-22 19:42:11 +00:00
Yash Rajput
89303690f2 Added SimplePendulumRK4 (#6800)
* Added SimplePendulumRK4

* Fixed build issue.

* Fixed build issue.

* Fixed build issue.
2025-10-21 20:18:32 +00:00
Indole Yi
d5289b92da Fix ConvexHull to return points in counter-clockwise order (#6810)
* Fix ConvexHull to return points in counter-clockwise order

- Add sortCounterClockwise method to ensure CCW ordering
- Start from bottom-most, left-most point for deterministic results
- Fix issue where unordered HashSet broke downstream algorithms
- Add comprehensive tests with CCW order verification

* test(geometry): Achieve 100% test coverage for ConvexHull
2025-10-19 18:17:19 +00:00
Indole Yi
4a97258189 feat(compression): Add LZW and Arithmetic Coding algorithms (#6799)
* feat(compression): Add LZW and Arithmetic Coding algorithms

* test(compression): Improve test coverage for LZW and ArithmeticCoding

* style(compression): fix code style
2025-10-19 18:11:22 +00:00
Yash Rajput
a7f0bab021 Adding ElasticCollision2D (#6802)
* Adding ElasticCollision2D

* Fixing build issues.
2025-10-19 17:00:32 +00:00
Saahil Mahato
b312567dc3 feat: add DDA line drawing algorithm (#6616)
* feat: add DDA line drawing algorithm

* refactor: clang formatting

---------

Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
2025-10-18 11:41:01 +00:00
Harshendu Swarnakar
6b7d201657 Hierholzer path algorithm (#6822)
* Added HierholzerEulerianPath algorithm

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

* Added Hierholzer Algorith to find Eulerian Path

---------

Co-authored-by: crashmovies <swarnakarharshendu420@gmail.com>
2025-10-17 23:53:26 +02:00
Hardik Pawar
4858ec9af0 refactor: Enhance docs, code, add tests in `MaximumSumOfDistinctSubar… (#6649)
* refactor: Enhance docs, code, add tests in `MaximumSumOfDistinctSubarraysWithLengthK`

* Fix

* Fix spotbug

* Fix

* Fix

* Fix

* Fix
2025-10-17 07:53:39 +00:00
Yash Rajput
e1773e9165 Adding DampedOscillator code (#6801)
* Adding DampedOscillator code

* Adding one more test case

* Adding one more test case

* Adding one more test case

* Fixing build issues.

* Fixing build issues.
2025-10-16 23:19:09 +02:00