Giter VIP home page Giter VIP logo

searching_algorithms's Introduction

Searching

Introduction:

Searching is a very important algorithm where the objective is to find if a given target element is present inside a given array.
If it is present, then it returns the index position of the element in the array.
If it is not present, then it returns None

Searching Algorithms

1) Linear Search (Sequential/Simple Search)
    - Start from the index 0 and continue till arr.length
    - Compare one by one with the target
    - If it matches, return the index
    - O(n)

2) Binary Search (Sublinear Search)
    - Assumes the array is sorted
    - Find mid point of arr
    - Compare arr[mid] with target
        - if matched, return mid
        - if arr[mid] > target, search in first half
        - else search in second half
    - O(log n)

Outputs

python3 search.py --range 10 --target 3 --search linear runtime = 1.7e-05 position = 3

python3 search.py --range 10 --target 3 --search binary runtime = 9e-06 position = 3

python3 search.py --range 1000 --target 300 --search linear runtime = 2.2e-05 position = 300

python3 search.py --range 1000 --target 300 --search binary runtime = 1e-05 position = 300

python3 search.py --range 100000 --target 900 --search linear runtime = 5.1e-05 position = 900

python3 search.py --range 100000 --target 900 --search binary runtime = 2.2e-05 position = 900

Conclusion

- Implemented Linear and Binary search in python
- Assumed input is a sorted array, so as to compare the search performance
- Binary search is better compared to Linear search

searching_algorithms's People

Contributors

gouherdanish avatar gouheraidash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.