Skip to content

Enhance sentinel_linear_search doctests with comprehensive examples#14284

Open
JesunAhmadUshno wants to merge 2 commits intoTheAlgorithms:masterfrom
JesunAhmadUshno:enhance-sentinel-search-doctests
Open

Enhance sentinel_linear_search doctests with comprehensive examples#14284
JesunAhmadUshno wants to merge 2 commits intoTheAlgorithms:masterfrom
JesunAhmadUshno:enhance-sentinel-search-doctests

Conversation

@JesunAhmadUshno
Copy link

Summary

Enhanced doctest coverage for sentinel_linear_search() with 15 comprehensive test examples covering:

  • Valid searches (first, middle, last element)
  • Invalid searches (element not found)
  • Edge cases (empty list, single-element list)
  • Type variations (integers, strings, floats, negative numbers)
  • Duplicates (finding first occurrence of duplicated values)

Changes

  • Added 11 new doctest examples (from 4 → 15 total)
  • Improved docstring documentation explaining the algorithm's sentinel approach
  • All tests pass locally: python -m doctest -v sentinel_linear_search.py

Checklist

  • I have read the CONTRIBUTING.md file
  • This is my own work and not plagiarized
  • My work will be distributed under the MIT License once merged
  • My submission follows the coding style and standards of this repository
  • I have tested my changes locally
  • All doctest examples pass
  • Code passes ruff linting

Copilot AI review requested due to automatic review settings February 17, 2026 10:45
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Feb 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR primarily aims to enhance documentation and doctest coverage, but it also includes several unrelated typing refactors and small cleanups across the repository.

Changes:

  • Expanded sentinel_linear_search() docstring and doctest examples (4 → 15).
  • Refactored type parameter declarations in jump_search() and valid_input() to use modern generic syntax.
  • Broadened bipartite-check graph typing to accept generic hashable nodes and updated handling for neighbor-only nodes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
searches/sentinel_linear_search.py Adds a more detailed algorithm explanation and many more doctest examples.
searches/jump_search.py Updates generic typing style and removes unused typing imports.
machine_learning/linear_discriminant_analysis.py Updates valid_input generic typing and removes TypeVar.
graphs/check_bipatrite.py Generalizes graph node types and changes semantics for neighbor-only nodes; removes FIXME doctest comments.
data_structures/hashing/hash_table_with_linked_list.py Minor cleanup: uses deque() instead of deque([]).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to 21
def jump_search[T: Comparable](arr: Sequence[T], item: T) -> int:
"""
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The PR title/description focuses on doctests for sentinel_linear_search(), but this change set also modifies typing/generics in other modules (e.g., jump_search, LDA valid_input, bipartite checks, hash table). Please update the PR description to reflect these changes or split them into separate PRs so review/rollback scope is clear.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines 33 to 39
>>> is_bipartite_dfs({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 4: [0]})
False
>>> is_bipartite_dfs({7: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 4: [0]})
False

>>> # FIXME: This test should fails with KeyError: 4.
>>> is_bipartite_dfs({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 9: [0]})
False
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

With the new behavior that neighbor nodes missing from graph are treated as having no outgoing edges, the example is_bipartite_dfs({7: ..., 4: [0]}) appears bipartite under the docstring definition, but the current algorithm returns False because it starts node 4 with an arbitrary color that can conflict with already-colored neighbor-only nodes. Consider choosing the start color based on any already-visited neighbors (or otherwise reconciling components), and update the doctest expected value accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines 112 to 117
False
>>> is_bipartite_bfs({7: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 4: [0]})
False

>>> # FIXME: This test should fails with KeyError: 4.
>>> is_bipartite_bfs({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 9: [0]})
False
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

Same issue as DFS: for graphs where some nodes appear only as neighbors (not keys), starting a new BFS component with color 0 can create a false conflict against an already-colored neighbor-only node (e.g., the {7: ..., 4: [0]} example). Initialize the component’s start color based on any already-colored neighbors (and verify consistency), or adjust the doctest/contract so the function’s behavior matches the documented bipartite definition.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines 17 to 24
@@ -18,6 +18,11 @@ def sentinel_linear_search(sequence, target):
:param target: item value to search
:return: index of found item or None if item is not found

The sentinel linear search algorithm works by appending the target value to the
end of the list before searching. This eliminates the need for boundary checking
during the loop, as the search is guaranteed to find the target (at minimum, at
the end where the sentinel is placed).
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The docstring describes sequence as “some sequence”, but the implementation requires a mutable list-like object because it calls append() and pop() and mutates the input (even if it restores it). Please clarify the accepted type (e.g., list/MutableSequence) and explicitly note the temporary mutation, or change the implementation to avoid mutating the caller’s object.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

@JesunAhmadUshno JesunAhmadUshno force-pushed the enhance-sentinel-search-doctests branch from a2dd3c3 to c8d6bab Compare February 17, 2026 10:53
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Feb 17, 2026
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.

1 participant