Skip to content

feat(datastructures): add SelfOrganizingLinkedList implementation and tests - #7575

Merged
DenizAltunkapan merged 27 commits into
TheAlgorithms:masterfrom
iamcodinghere22:feat/self-organizing-list
Aug 21, 2026
Merged

feat(datastructures): add SelfOrganizingLinkedList implementation and tests#7575
DenizAltunkapan merged 27 commits into
TheAlgorithms:masterfrom
iamcodinghere22:feat/self-organizing-list

Conversation

@iamcodinghere22

Copy link
Copy Markdown
Contributor

This PR implements the Self-Organizing Linked List data structure using the "Move To Front(MTF)" heuristic.
In this implementation, whenever an element is accessed/searched, it is dynamically moved to the head of the list. This optimizes access time for frequently requested items by keeping them near the front, achieving an {O(1)} best-case lookup time for repeated accesses.

Changes Included

  • Added SelfOrganizingLinkedList.java under com.thealgorithms.datastructures.lists.
  • Added comprehensive unit test coverage in SelfOrganizingLinkedListTest.java verifying search, insertion, edge cases (empty list, non-existent elements), and move-to-front behavior.

Testing

  • All unit tests in SelfOrganizingLinkedListTest.java pass locally (mvn test -Dtest=SelfOrganizingLinkedListTest).
  • Verified full build and test suite run successfully with JaCoCo code coverage.

Checklist

  • Code follows project coding guidelines.
  • Unit tests have been added for new functionality.
  • No duplicate code or classes introduced.

@codecov-commenter

codecov-commenter commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.62%. Comparing base (65b977e) to head (bf9575d).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7575      +/-   ##
============================================
+ Coverage     80.59%   80.62%   +0.02%     
- Complexity     7482     7496      +14     
============================================
  Files           815      816       +1     
  Lines         24062    24097      +35     
  Branches       4736     4741       +5     
============================================
+ Hits          19393    19428      +35     
  Misses         3906     3906              
  Partials        763      763              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@iamcodinghere22

Copy link
Copy Markdown
Contributor Author

Hi @DenizAltunkapan @yanglbme @alxkm,
All checks have passed successfully and the branch is ready.
Could one of you please review and approve this PR so it can be merged?
Thanks

@DenizAltunkapan DenizAltunkapan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, a self-organizing list with move-to-front is a good fit here and there's no existing one. The algorithm itself looks correct. A few things to sort out before this can go in, left inline.

@iamcodinghere22

Copy link
Copy Markdown
Contributor Author

@DenizAltunkapan
I’ve updated the implementation and tests to address all review comments:

Node Renaming:

Renamed LinkedList to Node and encapsulated it as a private static class Node nested within SelfOrganizingLinkedList.

Eliminates collision with java.util.LinkedList and keeps the file to a single top-level class per repository convention.

Getters (getSize & isEmpty):

Added assertions for getSize() and isEmpty() across initial, single-element, and multi-element states to achieve full coverage on Codecov.

Full List Integrity & Duplicate Handling:

Added test cases that walk the entire list order after Move-To-Front search operations to ensure no nodes are dropped and no cycles are created.

Added test coverage for list behavior when duplicate values exist.

@DenizAltunkapan DenizAltunkapan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DenizAltunkapan
DenizAltunkapan enabled auto-merge (squash) August 21, 2026 08:50
@DenizAltunkapan
DenizAltunkapan merged commit 9d05db2 into TheAlgorithms:master Aug 21, 2026
7 checks passed
@iamcodinghere22
iamcodinghere22 deleted the feat/self-organizing-list branch August 21, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants