My Datascience Journey
  • Home
  • Projects
  • Notes
  • Study
  • blogs
  • Python Package

  • Anomaly Detection
    • Anomaly Based IDS using ML
    • Anomaly Detection using online Event logs
    • Anomaly detection in dynamic graphs using MIDAS-R
    • Anomaly Detection using Unsupervised methods
  • 3D Deep Learning
    • 3D Data Formats
    • 3D coordination systems
    • 3D Rendering
    • Fitting Deformable Mesh Models to Raw Point Clouds
    • Differentiable Rendering
    • Neural Radiance Fields (NeRF)
    • Resources
  • ML Algorithms
    • Boosting
    • LogitBoost
    • Gradient Boosting
    • LightGBM
    • XGBoost
    • Catboost
  • Data Architecture
    • Big Data Architectures
    • Data Quality for ML
    • Feature Store
    • MLOPS
    • Model Deployment
    • Model Monitoring
  • Data Engineering
    • Azure Data Lake Storage Gen2
    • Azure Synapse Analytics
  • Transformers
    • Transformer Code Implementation
    • Computer Vision Using Transformers
    • Attention is all you need
    • Attention
    • Transformer
    • BERT
    • Transformers from Scratch
    • An Image is worth 16X16 Words
    • Vision Transformers (ViT)
    • How to Train Your ViT
    • Resources
  • Interpretable_ml
    • Introduction
    • Linear regression
    • Logistic Regression
    • Explainable Boosting Machines
    • Generalized Linear Models (GLM)
    • Decision Trees
    • Rulefit
    • Naive Bayes
    • Global Model Agnostic Methods
    • Local Model-Agnostic Methods
    • CNN Interpretation
    • Neural GAMs
    • Resources
    • Editable Interpretable Models
  • Linear Algebra
    • System of Linear Equations
    • Solving linear Equations
    • Vector Algebra
    • Linear Transformations
    • Determinants
    • Eigenvalues and Eigenvectors
    • linear_algebra/07_svd.qmd
    • Linear Algebra Resources
  • Graph Machine Learning
    • Graph Machine Learning
    • Resources
    • Graph Theory
  • Recommender Systems
    • Recommendation System Presentations
  • Industry Usecases
    • AI Use cases for the Insurance Industry
    • Powering OTT With Data Science
  • Bayesian Analysis
    • Bayesian Analysis
    • Resources
  • Causal Inference
    • Intro
    • Randomised Experiments
    • Stats Revisited
    • Graphical Causal Models
    • Packages
  • Computer Vision
    • Architecture for Image Classification
    • CNN Architectures
    • Coding Inception, ResNet and DenseNet Blocks
    • Object Detection - Part 1
    • Object Detection - Part 11
    • Anchor Boxes
    • Image Classification and Localization
    • You Only Look Once (YOLO)
    • Images Classification Implementation
    • Image Segmentation
    • Image Segmentation
    • Architecutures for Image segmentation
    • OneFormer: One Transformer to rule Universal Image Segmentation
  • NLP
    • Text Preprocessing
    • Information Extraction
    • RNN & LSTM
    • Starspace
    • Transformer Family of Models
    • Text Summarization
    • GPT
    • BERT
    • Chatbots
    • Question Answering (QA)
    • Algorithms for Chatbot
    • InstructGPT
    • Making Transformers efficient in Production
    • Instruction Finetuned Text Embeddings
  • Data Science Project Lifecycle
    • Sampling
    • Training
    • Feature Engineering
    • ML Algorithms
    • Gradient Descent
    • Regularization
    • Model Development
    • Why ML system fails
    • MlOps
    • Resources
  • Math for AI
    • Introduction
    • Distributions
    • Fitting functions to data
    • Gradient Descent, Activations and Regularisation
  • Time Series
    • Time Series Introduction
    • Exploratory Analysis
    • Simulating Time Series Data
    • Feature Engineering for Time Series
    • Feature Engineering for Time Series
    • ML for Time Series
    • packages for Time series
  • Geograhic Data Processing
    • Geographic Data
    • Visualizing Buildings in a location along with its Area
    • Spatial Analysis using Geopandas
    • Coordinate Reference Systems (CRS)
    • Data Visualization using Folium
    • OpenStreetMap
    • Converting Data from Raster to Tabular (Geometry) format
  • Machine learning Implementations
    • EDA on Telecom Churn Data
    • Telecom Churn Prediction
  • Data Quality
    • Ensuring Data Quality
    • Create a new Datasource
    • Initialize a new Expectation Suite by profiling a batch of your data.
    • Create Checkpoint
  • Unsupervised Machine Learning
    • Dimensionality Reduction
    • PCA
    • Singular Value Decomposition
    • Latent Dirichlet Allocation
    • Multi Dimensional Scaling
    • T-SNE (T distributed - Stochastic Neighbour Embedding)
  • Data Privacy
    • Approaches to Data privacy
    • Differential Privacy
  • Distributed Processing
    • Fugue
    • Fugue Quickstart
    • FugueSQL
  • Pytorch
    • Introduction to PyTorch
    • Simple Neural Network in Pytorch
    • Activation Functions
    • Pytorch Lightning
  • Python
    • Introduction to Dictionary
    • Iterating through a dictionary
    • Handling JSON in Python
    • Pandas 101
    • Pivot Table and Grouping in Pandas
  • DSA
    • Insertion Sort
    • Selection Sort
    • Bubble Sort
    • Merge Sort
    • Quick Sort
    • Binary Search
    • Binary Search Tree
    • Find Closest Value in BST
  • System Design
    • Step by Step Guide for System Design
    • Scaling web services to millions of users
  • probability
    • Probability
  • pyspark
    • Installing Spark
    • Hands-on Introduction to DataFrame API
    • Pandas API on Spark
    • Spark SQL
    • Tuning and Optimizing Spark
    • Spark Joins
    • Building Delta Lakes with Apache Spark
  • Why Me
    • Why me

On this page

  • Binary Search

Binary Search

Binary search using Iterative Method

# Time complexity O(log(n)) and space complexity is O(1)
### Using three pointers - left, right and middle
### We keep adjusting the three pointers and quit when 
### left pointer crosses the right pointer

def binarySearch(array, target):
    left = 0
    right = len(array) - 1    

    while left <= right:
        middle = (left+right) // 2
        potentialMatch = array[middle]

        if target == potentialMatch:
            return middle

        elif target < potentialMatch:
            right = middle - 1

        else:
            left = middle + 1

    return -1
array = [0,1,21,33,45,61,71,72,73]
target = 33
binarySearch(array=array,target=target)
3

Binary search using Recursion

# O(log(n)) time complexity ! O(log(n)) space complexity

def binarySearch(array,target):
    return binarySearchHelper(array,target,0,len(array)-1)

def binarySearchHelper(array,target,left,right):
    if left > right:
        return -1

    middle = (left+right) // 2
    potentialMatch = array[middle]
    if target == potentialMatch:
        return middle
    elif target < potentialMatch:
        return binarySearchHelper(array,target,left,middle-1)
    else:
        return binarySearchHelper(array,target,middle+1,right)  
binarySearch(array,target)
3
email: tulasiram.gunipati@gmail.com