TechieYan Technologies

Binary Search using python

Abstract

In this article we will be making a an algorithm for binary search. Binary Search is a search algorithm used in a sorted array by dividing the search range in two. The idea of binary research is to use the information that the table is sorted and reduce the time complexity to O (Log n).

Basic steps for creating an algorithm for binary search:

  • Start with the middle element in the entire array as the search key.
  • If the value of the search key is the same as the item, return an index of the search key.
  • Or if the search key is smaller than the element in the middle of the interval, reduce the interval to the lower half.
  • Otherwise, reduce them to the top half.
  • Check a number of times from the second point until the value is found or the interval is empty.
Binary Search using python result

Code Description & Execution

Programming Methodology

In this code, we will import random module. Make a function, in that make some parameters for avail the functionalities. By using if statement we take out the number from the given input. If the condition is  like high variable is equal to or greater than low variable. We will first add two variable then it should be divided by 2 to get the mid number. Then according to the input we the program will work like if it’s in middle it compare the values of output and get the results printed.

How to Execute?

Note: Make sure you have added path while installing the software’s.

https://techieyantechnologies.com/2022/07/how-to-install-anaconda/

https://techieyantechnologies.com/2022/06/get-started-with-creating-new-environment-in-anaconda-configuring-jupyter-notebook-and-installing-libraries-using-requirements-txt-2/

  1. Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.
  2. Press windows key and type in anaconda prompt a terminal opens up.
  3. Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
sending emails

4.<<directory of your file:>>. E.g., If my file is in d drive, then

5.Type d:

  1. cd d:\License-Plate-Recognition-main    #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE

          7. If your project is in c drive, you can ignore step 4 and go with step 5

          8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name” i.e., pip install pandas

Binary Search using python execution

      9. If you would like to run .ipynb file, Please follow the link to setup and open jupyter notebook, You will be redirected to the local server there you can select which ever .ipynb file you’d like to run and click on it and execute each cell one by one by pressing shift+enter.

Note: There are 4 different files each seeves different purpose such as,

  • ipynb consists of all the data cleaning steps, which are necessary to build a clean and efficient model.
  • ipynb consist of major steps and exploratory data analysis which allow us to understand more about the data and behavior of it.
  • ipynb consists of data reduction/dimensionality reduction techniques such as Sequential feature selector method to reduce the dimensions in the data and compare the model scores before and after dimensionality reduction.
  • ipynb consists of combination of main.ipynb and variable_selection.ipynb to make it more clear and understable for the audience.

Please follow the above sequence if you would like to execute and the files require good system requirements to run.

Results

Binary Search using python result

Issues Faced

  1. We might face an issue while installing specific libraries, in this case, you might need to install the libraires manually. Example: pip install “module_name/library” i.e., pip install wikipedia
  2. Make sure you have the latest or specific version of python, since sometimes it might cause version mismatch.
  3. Adding path to environment variables in order to run python files and anaconda environment in code editor, specifically in any code editor.
  4. Make sure to change the paths in the codeaccordingly where your music file and VS code is saved.

Refer to the Below links to get more details on installing python and anaconda and how to configure it.

https://techieyantechnologies.com/2022/07/how-to-install-anaconda/

https://techieyantechnologies.com/2022/06/get-started-with-creating-new-environment-in-anaconda-configuring-jupyter-notebook-and-installing-libraries-using-requirements-txt-2/

Note:

All the required data has been provided over here. Please feel free to contact me for model weights and if you face any issues.

https://techieyantechnologies.com/contact/

Yes, you now have more knowledge than yesterday, Keep Going.

+91 7075575787