P4-M 4/28 Binary Lesson HACKS
Learn the basics of binary including truth tables, boolean expressions, binary conversions, and binary searches.
Lesson Note Taker
Fill in the blanks below during the binary presentation. You can visit our website here!^ Due to last minute deployment issues, may need to run a local server
- git clone https://github.com/TheoH32/Runtime_Terror.git
- run:
- bundle install
- bundle exec jekyll serve
Binary
- Binary is a base 2 number system.
- 0 represents off and 1 represents on.
- A bit is the minimum unit of binary information stored in a computer system.
Boolean Expressions
- A boolean statement is a logical statement that is either TRUE or FALSE and compares data.
Truth Tables
- The logical operations shown in truth tables are AND, OR, NOT, NOR
# AND
5 > 3 and 5 == 3 + 2
5 < 3 and 5 == 5
5 == 5 or 5 != 5
5 < 3 or 5 != 5
age = 18
citizen = True
if age >= 18 and citizen:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Binary Conversions
Binary to Decimal
- We can count in binary by using powers of 2.
- In binary, we read from right to left.
- 0111 has a value of 7.
Binary Search
- For a binary search, the list must be sorted.
- In a binary search, computers start at the middle (front,middle,end).
- The number of steps required in a binary search follows the equation: log2(n).
- Binary searches also work with a list of strings. We can sort them alphabetically.
- Binary searches can be represented in flow diagrams.
Hacks
You will NOT be awarded any points for sections that are INCOMPLETE
Note Taker
- Fill in all of the blanks above.
Lesson Quiz
- Complete the lesson quiz
- SCREENSHOT SCORE and paste it here (or paste screenshot with submission)
Binary Game
- Complete the Binary game and reach a minimum score of 10!
- SCREENSHOT SCORE and paste it here (or with submission)
Binary Search Questions
-
Make a binary search tree of different the list [1,2,4,15,25,30,31]
15 / \ 2 30
/ \ / \ 1 4 25 31
- Put this list of strings in a order that can be used for binary search ["Donut”,"Cake”,"Soda”,"Banana”,"Fruit”]
- ["Banana", "Cake", "Donut", "Fruit", "Soda"]
- Explain why Binary Search is more efficient than Sequential Search.
- Binary Search is more efficient because instead of going through each element one by one, binary search searches half the elements and is able to eliminate half the set rather than eliminating one by one. Sequential search thus takes much more time as each element has to be examined while binary search is able to run faster.
1001010
Split into 3 groups:
1001010
001 (binary) = 1 (octal) 001 (binary) = 1 (octal) 010 (binary) = 2 (octal)
1001010 (binary) = 112 (octal)