Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: binary search first occurrence and resolve global ruff linting e…
…rrors
  • Loading branch information
tusharynayaka committed Mar 3, 2026
commit 4dc8470895154ba334403b9c1749360f9e7b2b3c
3 changes: 2 additions & 1 deletion searches/jump_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any

Check failure on line 1 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

searches/jump_search.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports
"""
Pure Python implementation of the jump search algorithm.
This algorithm iterates through a sorted collection with a step of n^(1/2),
Expand All @@ -8,9 +9,9 @@
https://en.wikipedia.org/wiki/Jump_search
"""

import math

Check failure on line 12 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

searches/jump_search.py:12:1: E402 Module level import not at top of file
from collections.abc import Sequence

Check failure on line 13 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F401)

searches/jump_search.py:13:29: F401 `collections.abc.Sequence` imported but unused help: Remove unused import: `collections.abc.Sequence`

Check failure on line 13 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

searches/jump_search.py:13:1: E402 Module level import not at top of file
from typing import Any, Protocol, TypeVar

Check failure on line 14 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F811)

searches/jump_search.py:14:20: F811 Redefinition of unused `Any` from line 1: `Any` redefined here searches/jump_search.py:1:20: previous definition of `Any` here help: Remove definition: `Any`

Check failure on line 14 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E402)

searches/jump_search.py:14:1: E402 Module level import not at top of file


class Comparable(Protocol):
Expand All @@ -20,7 +21,7 @@
T = TypeVar("T", bound=Comparable)


def jump_search[T](arr: Sequence[T], item: T) -> int:
def jump_search(arr: list[Any], x: Any) -> int:

Check failure on line 24 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (ARG001)

searches/jump_search.py:24:33: ARG001 Unused function argument: `x`
"""
Python implementation of the jump search algorithm.
Return the index if the `item` is found, otherwise return -1.
Expand All @@ -43,17 +44,17 @@

prev = 0
step = block_size
while arr[min(step, arr_size) - 1] < item:

Check failure on line 47 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

searches/jump_search.py:47:42: F821 Undefined name `item`
prev = step
step += block_size
if prev >= arr_size:
return -1

while arr[prev] < item:

Check failure on line 53 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

searches/jump_search.py:53:23: F821 Undefined name `item`
prev += 1
if prev == min(step, arr_size):
return -1
if arr[prev] == item:

Check failure on line 57 in searches/jump_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (F821)

searches/jump_search.py:57:21: F821 Undefined name `item`
return prev
return -1

Expand Down
Loading