Big Idea 5.5 Binary
Software Development using Frontend and Backend Technologies
Popcorn Hack #1:
Fill out the rest of the table and calculate what value is in binary: | Binary Digit | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ | |————–|—-|—-|—-|—-|—-|—-|—-|—-| | 1101 | | | 1 | 1 | 0 | 1 | | | | 10101010 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | | 01100110 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | | 11110000 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | | 00001111 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
Popcorn Hack #2: Binary Blitz!
Convert the following decimals into binary: 10, 15, 17
10 in Binary:
- 10 ÷ 2 = 5 → 0
- 5 ÷ 2 = 2 → 1
- 2 ÷ 2 = 1 → 0
- 1 ÷ 2 = 0 → 1
Binary 1010
15 in Binary:
- 15 ÷ 2 = 7 → 1
- 7 ÷ 2 = 3 → 1
- 3 ÷ 2 = 1 → 1
- 1 ÷ 2 = 0 → 1
Binary: 1111
17 in Binary:
- 17 ÷ 2 = 8 → 1
- 8 ÷ 2 = 4 → 0
- 4 ÷ 2 = 2 → 0
- 2 ÷ 2 = 1 → 0
- 1 ÷ 2 = 0 → 1
Binary: 10001
🍿 Popcorn Hack #3: Half & Half!
Given this sequence:
[3, 6, 9, 12, 15, 18, 21, 24]
How do you search for the number 18?
- Start with the whole list.
- Find the middle element.
- If it’s 18, you are done.
- If it’s less than 18, search the right half.
- If it’s greater than 18, search the left half.
HOMEWORK HACKS
PART A: Binary Breakdown
Convert: 42
Division by 2:
42 ÷ 2 = 21 → 0
21 ÷ 2 = 10 → 1
10 ÷ 2 = 5 → 0
5 ÷ 2 = 2 → 1
2 ÷ 2 = 1 → 0
1 ÷ 2 = 0 → 1
Binary: 101010
Place Value Table:
| 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ | |—-|—-|—-|—-|—-|—-| | 1 | 0 | 1 | 0 | 1 | 0 |
Convert: 19
Division by 2:
19 ÷ 2 = 9 → 1
9 ÷ 2 = 4 → 1
4 ÷ 2 = 2 → 0
2 ÷ 2 = 1 → 0
1 ÷ 2 = 0 → 1
Binary: 10011
Place Value Table:
| 2⁴ | 2³ | 2² | 2¹ | 2⁰ | |—-|—-|—-|—-|—-| | 1 | 0 | 0 | 1 | 1 |
Convert: 100
Division by 2:
100 ÷ 2 = 50 → 0
50 ÷ 2 = 25 → 0
25 ÷ 2 = 12 → 1
12 ÷ 2 = 6 → 0
6 ÷ 2 = 3 → 0
3 ÷ 2 = 1 → 1
1 ÷ 2 = 0 → 1
Binary: 1100100
Place Value Table:
| 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ | |—-|—-|—-|—-|—-|—-|—-| | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
PART B: Binary to Decimal Sprint
Convert: 101010
2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
---|---|---|---|---|---|
1 | 0 | 1 | 0 | 1 | 0 |
Math: 32 + 8 + 2 = 42
Convert: 10011
2⁴ | 2³ | 2² | 2¹ | 2⁰ |
---|---|---|---|---|
1 | 0 | 0 | 1 | 1 |
Math: 16 + 2 + 1 = 19
Convert: 110011
2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
---|---|---|---|---|---|
1 | 1 | 0 | 0 | 1 | 1 |
Math: 32 + 16 + 2 + 1 = 51
PART C: Binary Search in Action
List:
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33]
Search for 18
- Mid = index 5 → 18
Found in 1 comparison
Search for 33
- Mid = 5 → 18
- Search right → Mid = 8 → 27
- Search right → Mid = 10 → 33
Found in 3 comparisons
Search for 5
- Mid = 5 → 18
- Search left → Mid = 2 → 9
- Search left → Mid = 0 → 3
- Search right → index 1 = 6
Not Found
4 comparisons
PART D: Binary Search with Strings
List:
["apple", "banana", "carrot", "dragonfruit", "fig", "grape", "kiwi", "mango", "orange", "peach", "watermelon"]
Search for “mango”
- Mid = index 5 → “grape”
- Search right → Mid = 8 → “orange”
- Search left → Mid = 6 → “kiwi”
- Search right → index 7 = “mango”
Found in 4 comparisons
Search for “carrot”
- Mid = 5 → “grape”
- Search left → Mid = 2 → “carrot”
Found in 2 comparisons
Search for “lemon”
- Mid = 5 → “grape”
- Search right → Mid = 8 → “orange”
- Search left → Mid = 6 → “kiwi”
- Search right → index 7 = “mango”
“lemon” not found between “kiwi” and “mango”
5 comparisons, not found
Free Response Questions
Why is binary search more efficient for large data than linear search?
Binary search splits the list in half each time, so it finds things faster—especially when the list is large. Linear search checks every single item one by one, which takes longer.
What happens if the list isn’t sorted and you try to use binary search?
It won’t work properly. Binary search depends on the list being sorted. If it’s not, the results can be wrong or the item might be missed.
Could you use binary search in a video game leaderboard or streaming service search bar? Why or why not?
Yes, if the data is sorted. Binary search can quickly find names, titles, or scores, which helps load results faster and improve the user experience.