Source code for pythorn.data_structures.searching

"""
Author : Robin Singh

Programs List : 
1 . Binary Search (Iterative Method)
2 . Fibonacci Search
3 . Interpolation Search
4 . Jump Search
5 . Linear Search

"""

import inspect
from pythorn.data_structures.recursion import fibonacci
import math


[docs]class BinarySearch(object): """ Binary Search Implementation """ def __init__(self, array=None, key=None): """ :param array: array of elements :param key: key to be search in the given array """ self.array = array self.key = key
[docs] @staticmethod def get_code(): """ :return: source code """ return inspect.getsource(BinarySearch)
[docs] @staticmethod def time_complexity(): """ :return: time complexity """ return " Best Case : O(1), "\ " Worst Case: O(Logn), "\ " Average Case: O(Logn) "
[docs]class FibonacciSearch(object): """ Fibonacci Search Implementation """ def __init__(self, array=None, key=None): """ :param array: array of elements :param key: key to be search in the given array """ self.array = array self.key = key
[docs] @staticmethod def get_code(): """ :return: source code """ return inspect.getsource(FibonacciSearch)
[docs] @staticmethod def time_complexity(): """ :return: time complexity """ return " Best Case : O(1) , "\ " Worst Case: O(Logn), "\ " Average Case: O(Logn) "
[docs]class InterpolationSearch(object): """ Interpolation Search Implementation """ def __init__(self, array=None, key=None): """ :param array: array of elements :param length: length of array :param key: key to be search in the given array """ self.array = array self.length = len(array) self.key = key
[docs] @staticmethod def get_code(): """ :return: source code """ return inspect.getsource(InterpolationSearch)
[docs] @staticmethod def time_complexity(): """ :return: time complexity """ return " Best Case : O(1) , "\ " Worst Case: O(n), "\ " Average Case: O(Log Logn) "
[docs]class JumpSearch(object): """ Jump Search Implementation """ def __init__(self, array=None, key=None): """ :param array: array of elements :param key: key to be search in the given array """ self.array = array self.key = key
[docs] @staticmethod def get_code(): """ :return: source code """ return inspect.getsource(JumpSearch)
[docs] @staticmethod def time_complexity(): """ :return: time complexity """ return " Best Case : O(1) , "\ " Worst Case: O(√n), "\ " Average Case: O(√n)"
[docs]class LinearSearch(object): """ Linear Search Implementation """ def __init__(self, array=None, key=None): """ :param array: array of elements :param key: key to be search in the given array """ self.array = array self.key = key
[docs] @staticmethod def get_code(): """ :return: source code """ return inspect.getsource(LinearSearch)
[docs] @staticmethod def time_complexity(): """ :return: time complexity """ return " Best Case : O(1) , "\ " Worst Case: O(N), "\ " Average Case: O(N)"