Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion maths/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
https://en.wikipedia.org/wiki/Fibonacci_number for more information
"""

import functools
from collections.abc import Iterator
from math import sqrt
from time import time

import numpy as np
from numpy import ndarray

from typing import Any

Check failure on line 25 in maths/fibonacci.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

maths/fibonacci.py:17:1: I001 Import block is un-sorted or un-formatted help: Organize imports

def time_func(func, *args, **kwargs):

def time_func(func, *args, **kwargs) -> Any:
"""
Times the execution of a function with parameters
"""

start = time()
output = func(*args, **kwargs)
end = time()
Expand Down
26 changes: 10 additions & 16 deletions searches/linear_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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)
Expand All @@ -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:
Expand Down
Loading