⚡ BINARY SEARCH VISUALIZER
User Input • LOW • MID • HIGH • Animation • Comparisons
```
📥 Enter Your Data
```
```
📊 Sorted Array
Binary Search works on a sorted array. Your values will be sorted automatically.
```
```
```
📈 Search Statistics
Target
-
LOW
-
MID
-
HIGH
-
Comparisons
0
```
```
📝 Step-by-Step Explanation
1
Enter the values and target, then click
START SEARCH.
```
🧮 Binary Search Mathematics
Middle Position:
MID = ⌊(LOW + HIGH) / 2⌋
If TARGET = A[MID] → FOUND
If TARGET < A[MID] → HIGH = MID − 1
If TARGET > A[MID] → LOW = MID + 1
```
MID = ⌊(LOW + HIGH) / 2⌋
If TARGET = A[MID] → FOUND
If TARGET < A[MID] → HIGH = MID − 1
If TARGET > A[MID] → LOW = MID + 1
```
💡 How Binary Search Works
```
START
↓
LOW = 0
HIGH = n - 1
↓
MID = floor((LOW + HIGH) / 2)
↓
Compare TARGET with A[MID]
↓
TARGET == A[MID]
→ FOUND
↓
TARGET < A[MID]
→ HIGH = MID - 1
↓
TARGET > A[MID]
→ LOW = MID + 1
↓
Repeat
↓
LOW > HIGH
→ NOT FOUND
```
```
```
📚 Understanding the Animation
🔵 LOW = starting position of the
current search range.
🟣 HIGH = ending position of the current search range.
🟡 MID = middle position being checked.
🟢 FOUND = target has been located.
⚪ Faded elements = eliminated from the search range.
```
🟣 HIGH = ending position of the current search range.
🟡 MID = middle position being checked.
🟢 FOUND = target has been located.
⚪ Faded elements = eliminated from the search range.
```
⏱️ Time Complexity
Best Case: O(1)
Target is found at the first MID.
Average Case: O(log n)
Worst Case: O(log n)
The search range is repeatedly divided by two.
Space Complexity: O(1) for the iterative algorithm.
```
Target is found at the first MID.
Average Case: O(log n)
Worst Case: O(log n)
The search range is repeatedly divided by two.
Space Complexity: O(1) for the iterative algorithm.
No comments:
Post a Comment