🎯 Goals:
-
Understand Linear Search and Binary Search
-
Learn when and how to use each
-
Solve real interview problems using searching techniques
🔍 1. Linear Search
📘 Definition:
Linearly checks each element one by one. Used when the array is unsorted.
✅ Code Example:
🧠 2. Binary Search
📘 Definition:
Used on sorted arrays. It divides the search space in half each time — O(log N) time complexity.
✅ Code (Iterative Approach):
✅ Code (Recursive Approach):
💡 3. Binary Search Use Cases
-
Search in sorted array
-
Find first/last occurrence of an element
-
Search in rotated sorted arrays
-
Peak elements in mountain arrays
✍️ 4. Practice Problems
🔹 Write functions to:
-
Find first and last occurrence of an element (e.g. in sorted duplicates)
-
Count how many times a number appears in sorted array
-
Search in a rotated sorted array
-
Find square root using binary search (approximate to floor)
🔥 5. BONUS – Search in 2D Matrix
🔹 Use binary search logic on 2D:
📚 Homework for Day 3:
-
Implement both linear and binary search
-
Solve 2 problems from LeetCode:
-
Explore: Lower Bound, Upper Bound (optional but forward-thinking)
⏭️ What’s Coming on Day 4?
-
Sorting Algorithms: Bubble, Selection, Insertion (with time/space analysis)
Comments
Post a Comment