Searching

Learning searching algorithms easily!

Quick Start Guide

# import the required searching algorithm
from pygorithm.searching import binary_search

my_list = [12, 4, 2, 14, 3, 7, 5]

# pre-requisite for binary search is that the list should be sorted
my_list.sort()

# to search an element in the above list
index = binary_search.search(my_list, 7)
print(index)

Features

  • Searching algorithms available:
    • Linear Search (linear_search)
    • Binary Search (binary_search)
    • Breadth First Search (breadth_first_search)
    • Depth First Search (depth_first_search)
  • To see all the available functions in a module, you can just type help() with the module name as argument. For example,
>>> from pygorithm import searching
>>> help(searching)
        Help on package pygorithm.searching in pygorithm:

        NAME
        pygorithm.searching - Collection of searching algorithms

        PACKAGE CONTENTS
        binary_search
        breadth_first_search
        depth_first_search
        linear_search
        modules
        quick_select
  • For Searching: Remember search() function in binary_search module takes two parameters as a sorted list and the target element to be searched.
# import the required searching algorithm
from pygorithm.searching import binary_search

my_list = [12, 4, 2, 14, 3, 7, 5]

# pre-requisite for binary search is that the list should be sorted
my_list.sort()

# to search an element in the above list
index = binary_search.search(my_list, 7)
print(index)
  • Get time complexities of all the searching algorithms
from pygorithm.searching import binary_search

# for printing time complexities of binary_search
print(binary_search.time_complexities())
  • Get the code used for any of the algorithm
from pygorithm.searching import binary_search

# for printing the source code of bubble_sort
print(binary_search.get_code())