Lecture 35 – Unit 6 – Under the Hood Binary Encoding – Part 1 CMPT 120 Lecture 35 – Unit 6 – Under the Hood Binary Encoding – Part 1
Homework - What does Big O Notation tell us? What if I have 5 algorithms (or functions) that do the same thing, for example, extract red jelly beans from a bag of multicolour jelly beans Algorithm A -> O(1) Algorithm B -> O(n) Algorithm C -> O(log2 n) Algorithm D -> O(n log2 n) Algorithm E -> O(n!) Which one is the fastest?
Homework – What does Big O Notation tell us? # of comparisons https://en.wikipedia.org/wiki/Big_O_notation
Complexity of Selection Sort Selection Sort looks for the smallest element multiple times, by going through n elements, then n-1 elements, then n-2 elements, … The total number of comparisons is therefore = n + (n-1) + (n-2) + … + 3 + 2 + 1 = n (n + 1) 2 = n2 + n 2 2 Computing scientists mainly care about the highest order term. Therefore we consider selection sort to be quadratic -> O(n2)
Unit 6. Under The Hood Ever wonder how computers represent data? You got it! -> Computers use 0 and 1 to represent everything In this module, we shall discover Why computers use 0 and 1 to represent everything How they do it Binary Numeral System
Unit 6. Under The Hood
Let’s open the hood! Source: http://ryanscomputersystem.blogspot.com/p/data-flow-diagram.html
Main Memory
“Computers use 0 and 1 to represent everything“ Computer memory: 100100111010010001000100010001000100010001100010010101000111111010010010001000100110010001011011100100100100100100100000000110010100101010101000100100100100010001001100100010110111001001011101001010101010001001011000010100010011001000101101110010010101 010010010010010101001 integer colour floating point number character CPU instruction sound
Why the 0’s and the 1’s Fundamentally, digital computers are machines that convert high and low electrical signals (called voltage) into 0’s and 1’s. Let’s learn to speak its native language!
Decimal numeral system Binary numeral system Decimal -> 10 (Base 10) Ten symbols (digits): Positional system When counting: Binary -> 2 (Base 2) Two symbols (bits): (bits -> binary digits) Positional system When counting:
How computers represent characters Source: http://1.bp.blogspot.com/_e8aZh22zXKM/TMeR_fFL8aI/AAAAAAAAAAo/pIR08vVLkz0/s320/Hello_World.jpg See ASCII Table: https://www.ascii-code.com/
How computers represent integers Which integer is : bit byte A bit either contains a 0 or 1 A byte is 8 bits
Next Lecture More about Binary Numeral System Binary -> Decimal Decimal -> Binary