Uh oh!
There was an error while loading. Please reload this page.
Jump search - #2415
Conversation
| def jump_search(arr, x): | ||
| def jump_search(arr: list, x: int) -> int: |
There was a problem hiding this comment.
| defjump_search(arr: list, x: int) ->int: | |
| defjump_search(arr: List[int], x: int) ->int: |
First import List from typing
There was a problem hiding this comment.
This limits us to only the int data type. Without this specificity, would the algorithm work with strings, tuples, floats?
| user_input = input("Enter numbers separated by a comma:\n").strip() | ||
| arr = [int(item) for item in user_input.split(",")] | ||
| x = int(input("Enter the number to be searched:\n")) | ||
| print(f"Number {x} is at index {jump_search(arr, x)}") |
There was a problem hiding this comment.
-1 is a valid position in python, check if the number is found before printing it
TravisBuddy
commented
Sep 11, 2020
Hey @BriseBalloches, TravisCI finished with status TravisBuddy Request Identifier: 1fc95270-f450-11ea-a882-ef0b60d9fbb3 |
grochedix
commented
Sep 11, 2020
Modified. Thanks. |
| >>> jump_search([-5, -2, -1], -1) | ||
| 2 | ||
| >>> jump_search([0, 5, 10, 20], 8) | ||
| -1 |
There was a problem hiding this comment.
I tend to like to raise an exception like str.index() vs str.find() but that is a personal choice.
* jump_search: doctest, docstring, type hint, inputs * jumpsearch.py: case number not found * trailing whitespace jump search
Describe your change:
Added type hinting, docstring, doctest for jump search algorithm.
Checklist:
Fixes: #{$ISSUE_NO}.