Binary Search Algorithm Explanation

Imagine searching for a number in a list of 1 million sorted numbers. Would you check them one by one? Or eliminate half of the list every step? 🚀 Day 74/365 — DSA Challenge Solved: Binary Search The Problem You're given a sorted array and a target value. Return the index of the target if it exists. Otherwise return -1. 💡 The Idea Behind Binary Search Binary Search works by dividing the search space in half every step. Steps: 1️⃣ Start with the middle element 2️⃣ If it equals the target → return index 3️⃣ If target is larger → search right half 4️⃣ If target is smaller → search left half Repeat until the element is found. ⏱ Time: O(log n) 📦 Space: O(1) Day 74/365 complete. 💻 291 days to go. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #Algorithms #BinarySearch #LearningInPublic

  • text

I salute your consistency bro 🫡🫡🫡

To view or add a comment, sign in

Explore content categories