From 1c57978fefaea1bafbf4fabc949080fb4a5e6a11 Mon Sep 17 00:00:00 2001 From: snehapriy958 Date: Mon, 4 May 2026 10:23:19 +0530 Subject: [PATCH 1/4] Fix: improve docstrings and use ValueError in rec_linear_search --- searches/linear_search.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/searches/linear_search.py b/searches/linear_search.py index 8adb4a7015f0..6e3775a1375e 100644 --- a/searches/linear_search.py +++ b/searches/linear_search.py @@ -12,18 +12,13 @@ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm - :param sequence: a collection with comparable items (sorting is not required for - linear search) - :param target: item value to search - :return: index of found item or -1 if item is not found + :param sequence: a collection with comparable items (No sorting required) + :param target: Value to search for + :return: index of target if found, else -1 Examples: >>> linear_search([0, 5, 7, 10, 15], 0) 0 - >>> linear_search([0, 5, 7, 10, 15], 15) - 4 - >>> linear_search([0, 5, 7, 10, 15], 5) - 1 >>> linear_search([0, 5, 7, 10, 15], 6) -1 """ @@ -35,14 +30,13 @@ def linear_search(sequence: list, target: int) -> int: def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: """ - A pure Python implementation of a recursive linear search algorithm + Recursive linear search algorithm - :param sequence: a collection with comparable items (as sorted items not required - in Linear Search) - :param low: Lower bound of the array - :param high: Higher bound of the array - :param target: The element to be found - :return: Index of the key or -1 if key not found + :param sequence: Collection of comparable items (no sorting required) + :param low: Lower index bound + :param high: Higher index bound + :param target: Value to search for + :return: Index of the target if found, else -1 Examples: >>> rec_linear_search([0, 30, 500, 100, 700], 0, 4, 0) @@ -55,7 +49,7 @@ def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: -1 """ if not (0 <= high < len(sequence) and 0 <= low < len(sequence)): - raise Exception("Invalid upper or lower bound!") + raise ValueError("Invalid upper or lower bound!") if high < low: return -1 if sequence[low] == target: From 9baa3af6c74b540b5d2e91ec1d08151e58b6cabd Mon Sep 17 00:00:00 2001 From: snehapriy958 Date: Mon, 4 May 2026 15:05:07 +0530 Subject: [PATCH 2/4] Fix: align error message with datasets --- maths/fibonacci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/fibonacci.py b/maths/fibonacci.py index 595233cf8446..b311c8fd863b 100644 --- a/maths/fibonacci.py +++ b/maths/fibonacci.py @@ -23,10 +23,11 @@ from numpy import ndarray -def time_func(func, *args, **kwargs): +def time_func(func, *args, **kwargs) -> object: """ Times the execution of a function with parameters """ + start = time() output = func(*args, **kwargs) end = time() From 34279a27059e252dec288f508a387fc8a49e5872 Mon Sep 17 00:00:00 2001 From: snehapriy958 Date: Mon, 4 May 2026 15:14:33 +0530 Subject: [PATCH 3/4] Improve: align error message with doctests --- maths/fibonacci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/fibonacci.py b/maths/fibonacci.py index b311c8fd863b..94006bb08ec3 100644 --- a/maths/fibonacci.py +++ b/maths/fibonacci.py @@ -22,8 +22,9 @@ import numpy as np from numpy import ndarray +from typing import Any -def time_func(func, *args, **kwargs) -> object: +def time_func(func, *args, **kwargs) -> Any: """ Times the execution of a function with parameters """ From 656c4b7e781c9aa8ea54c50fc331a1e784fedd80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 May 2026 09:49:51 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/fibonacci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/fibonacci.py b/maths/fibonacci.py index 94006bb08ec3..7db1ebb7fa55 100644 --- a/maths/fibonacci.py +++ b/maths/fibonacci.py @@ -24,11 +24,12 @@ from typing import Any + def time_func(func, *args, **kwargs) -> Any: """ Times the execution of a function with parameters """ - + start = time() output = func(*args, **kwargs) end = time()