- 2068 Bhadra · 3 marks
Binary search for 89; hash functions
Short answer
Compare with middle: mid=6 (50) → low=7; mid=9 (85) → low=10; mid=11 (94) → high=10; mid=10 (89) → found at index 10 after 4 steps.
Use binary search to find 89 from the data: 8, 12, 20, 24, 30, 45, 50, 68, 72, 85, 89, 94, 98.
Data (index 0 to 12): 8, 12, 20, 24, 30, 45, 50, 68, 72, 85, 89, 94, 98. Key = 89.
| Step | low | high | mid | a[mid] | Decision |
|---|---|---|---|---|---|
| 1 | 0 | 12 | 6 | 50 | 89 > 50, so low = 7 |
| 2 | 7 | 12 | 9 | 85 | 89 > 85, so low = 10 |
| 3 | 10 | 12 | 11 | 94 | 89 < 94, so high = 10 |
| 4 | 10 | 10 | 10 | 89 | equal, found |
Answer: 89 is found at index 10 (11th position) after 4 steps. (mid = ⌊(low + high)/2⌋ at each step.)
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- AVL tree for 10 20 30 50 45 40 8 5 3 · Data Structure and Algorithm, chapter 6
- Binary search for 54 in sorted data · Data Structure and Algorithm, chapter 8
- Hashing and different hash functions · Data Structure and Algorithm, chapter 8
- AVL tree for 52, 65, 72, 15, 11, 32, 20 · Data Structure and Algorithm, chapter 6
- Binary search with algorithm and example · Data Structure and Algorithm, chapter 8 · asked 4×
- Complexity of binary search · Data Structure and Algorithm, chapter 8
- Theodolite traverse ABCDA with missing VCR (68°30′10″) · Surveying I, chapter 7
- Subnet 202.77.19.0/24 for 30, 24, 25, 20 · Computer Networks and Security, chapter 4
- Volume from central depths 1.85, 2.15, 2.45 · Surveying I, chapter 9
- Round robin scheduling (53, 17, 68, 24 ms) · Embedded System, chapter 6 · asked 4×