Skip to content

Enhance exponential_search doctests with comprehensive examples#14286

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

Enhance exponential_search doctests with comprehensive examples#14286
JesunAhmadUshno wants to merge 2 commits intoTheAlgorithms:masterfrom
JesunAhmadUshno:enhance-exponential-search-doctests

Conversation

@JesunAhmadUshno
Copy link

Summary

Enhanced doctest coverage for exponential_search() with 14 comprehensive test examples covering:

  • Valid searches (first, middle, last elements)
  • Invalid searches (element not found)
  • Edge cases (single-element list)
  • Various array sizes (small, large ranges)
  • Different value distributions
  • Large arrays (up to 100 elements)

Changes

  • Added 10 new doctest examples (from 4 → 14 total)
  • Improved docstring to explain the exponential doubling strategy
  • Added complexity notes (O(log i) where i is the index)
  • All tests pass locally

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 11:01
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels 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 enhances documentation and doctest coverage around exponential_search(), and also includes a handful of broader typing/documentation cleanups in other modules.

Changes:

  • Expanded exponential_search() docstring with additional explanation, complexity notes, and 10 new doctest examples.
  • Migrated some type annotations to PEP 695 generic syntax (jump_search, valid_input) and generalized bipartite graph function typing.
  • Minor small refactor in hash table linked-list storage (deque([])deque()).

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/jump_search.py Updates generic typing syntax for jump_search() and removes the old TypeVar declaration.
searches/exponential_search.py Adds more explanatory docstring text and expands doctest examples from 4 to 14.
machine_learning/linear_discriminant_analysis.py Updates valid_input() typing to PEP 695 generic syntax and removes TypeVar usage/import.
graphs/check_bipatrite.py Broadens accepted graph typing to hashable nodes and updates docs/annotations for DFS/BFS variants.
data_structures/hashing/hash_table_with_linked_list.py Minor simplification of deque construction in _set_value.

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

Comment on lines 15 to +17
Checks if the graph can be divided into two sets of vertices, such that no two
vertices within the same set are connected by an edge.
vertices within the same set are connected by an edge. Neighbor nodes that do
not appear as keys are treated as isolated nodes with no outgoing edges.
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.

Docstring says neighbor nodes not appearing as keys are treated as “isolated nodes,” but those nodes can still have incoming edges (they just have no outgoing adjacency list). Consider rewording to “treated as nodes with no outgoing edges/neighbor list” to match the behavior more precisely.

Copilot uses AI. Check for mistakes.
Comment on lines 93 to +95
Check if the graph can be divided into two sets of vertices, such that no two
vertices within the same set are connected by an edge.
vertices within the same set are connected by an edge. Neighbor nodes that do
not appear as keys are treated as isolated nodes with no outgoing edges.
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.

Docstring says neighbor nodes not appearing as keys are treated as “isolated nodes,” but those nodes can still have incoming edges (they just have no outgoing adjacency list). Consider rewording to “treated as nodes with no outgoing edges/neighbor list” to match the behavior more precisely.

Copilot uses AI. Check for mistakes.
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 focus on enhancing exponential_search() doctests, but this PR also changes type syntax in jump_search, updates typing in linear_discriminant_analysis.valid_input, adjusts bipartite graph typing/docs, and tweaks a hash table implementation. Please update the PR title/description to reflect the full scope or split these unrelated changes into separate PRs for easier review and revertability.

Copilot uses AI. Check for mistakes.

Exponential search (also called doubling search) works by finding a range where
the target element may be located, then performing a binary search within that range.
It's particularly efficient for unbounded or infinite arrays.
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 says exponential search is “particularly efficient for unbounded or infinite arrays,” but this implementation requires a finite, sized list (it uses len() and direct indexing). Consider rephrasing to avoid implying this function works on truly unbounded/infinite collections.

Suggested change
It's particularly efficient for unbounded or infinite arrays.
In theory, exponential search is particularly useful for unbounded or very large
sorted collections, but this implementation operates on finite Python lists.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant