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

  1. git clone https://github.com/TheoH32/Runtime_Terror.git
  2. run:
  • bundle install
  • bundle exec jekyll serve

Binary

  1. Binary is a base 2 number system.
  2. 0 represents 1 and 1 represents 2.
  3. A byte is the minimum unit of binary information stored in a computer system.

Boolean Expressions

  1. A boolean experssion is a logical statement that is either TRUE or FALSE and compares data.

Truth Tables

  1. The logical operations shown in truth tables are and, or, not, and xor.
# AND
5 > 3 and 5 == 3 + 2
True
5 < 3 and 5 == 5
False
5 == 5 or 5 != 5
True
5 < 3 or 5 != 5
False

Real Life Example using Boolean Expressions

Try changing the conditions and/or the logical operation below! Run the code to see if you are eligible to vote.

age = 18
citizen = True

if age >= 18 and citizen:
    print("You are eligible to vote.")
else:
    print("You are not eligible to vote.")
You are eligible to vote.

Binary Conversions

Binary to Decimal

  1. We can count in binary by using powers of 2.
  2. In binary, we read from right to left.
  3. 0111 has a value of 7.
  1. For a binary search, the list must be sorted.
  2. In a binary search, computers start at the front (front,middle,end)/
  3. The number of steps required in a binary search follows the equation: log2(n)+1.
  4. Binary searches also work with a list of strings. We can sort them alphabetically.
  5. Binary searches can be represented in Tree diagrams.

Hacks

You will NOT be awarded any points for sections that are INCOMPLETE

Note Taker

  1. Fill in all of the blanks above.

Lesson Quiz

  1. Complete the lesson quiz
  2. SCREENSHOT SCORE and paste it here (or paste screenshot with submission)' img ### Binary Game

  3. Complete the Binary game and reach a minimum score of 10!

  4. SCREENSHOT SCORE and paste it here (or with submission) img

Binary Conversions Practice

  1. How do you convert the decimal number "17" into binary? Answer: Divide 17 by 2 repeatedly and write the remainders in reverse order: 10001.

  2. How do you convert the binary number 1010 into decimal? Answer: Multiply each digit by its corresponding power of 2 and sum the results: 10.

  3. How do you convert the decimal number "122" into hexadecimal? Answer: Divide 122 by 16 repeatedly and write the remainders in reverse order: 7A.

  4. How do you convert the hexadecimal number "09" into binary? Answer: Replace each digit with its 4-bit binary equivalent: 1001.

Binary Search Questions

  1. Make a binary search tree of different the list [1,2,4,15,25,30,31]
  2. Put this list of strings in a order that can be used for binary search ["Donut”,"Cake”,"Soda”,"Banana”,"Fruit”]
  3. Explain why Binary Search is more efficient than Sequential Search.
    • Binary search is more efficient than sequential search because it has a time complexity of O(log n) whereas sequential search has a time complexity of O(n).
class Node:
    def __init__(self, val):
        self.left = None
        self.right = None
        self.val = val
        
def insert(root, val):
    if not root:
        return Node(val)
    elif root.val < val:
        root.right = insert(root.right, val)
    else:
        root.left = insert(root.left, val)
    return root

def inorder(root):
    if root:
        inorder(root.left)
        print(root.val)
        inorder(root.right)
        
# Create a binary search tree from a list
list1 = [1, 2, 4, 15, 25, 30, 31]
root = None
for i in list1:
    root = insert(root, i)

# Print the inorder traversal of the binary search tree
inorder(root)

# Given list of strings
list2 = ["Donut", "Cake", "Soda", "Banana", "Fruit"]

# Sort the list alphabetically
list2.sort()

# Print the sorted list
print(list2)
1
2
4
15
25
30
31
['Banana', 'Cake', 'Donut', 'Fruit', 'Soda']

Extra Credit:

  • Translate the binary number, 1001010, into octal (base 8). SHOW YOUR WORK AND EXPLAIN YOUR THINKING. OR
  • write the best rap line (determined during the lesson by group)

Hacks Scoring

Hack Comments Grade
Note Taker fill in the blanks above 0.1
Lesson Quiz under 100% = 0.1 only 0.2
Binary Game must score at least 10 points 0.2
Binary Conversions Practice if incorrect= 0.2 awarded 0.2
Binary Search Questions if incorrect= 0.2 awarded 0.2
Extra Credit MUST SHOW WORK 0.1
Total expected= 0.9/1 1/1