winter 2016 comp-250: introduction to computer...
TRANSCRIPT
Winter 2016COMP-250: Introduction
to Computer ScienceLecture 3, January 19, 2016
Thu 10:00Thu 10:30Thu 11:00
Mon 11:30 Tue 11:30 Wed 11:30 Thu 11:30 Fri 11:30Mon 12:00 Tue 12:00 Thu 12:00Mon 12:30 Tue 12:30 Thu 12:30Mon 13:00 13:00Mon 13:30 WED 13:30Mon 14:00 WED 14:00Mon 14:30 Tue 14:30 WED 14:30 Thu 14:30Mon 15:00 Tue 15:00 Wed 15:00 Fri 15:00Mon 15:30 Tue 15:30 Wed 15:30 Fri 15:30Mon 16:00 Tue 16:00 Wed 16:00 Fri 16:00
DoYeonTR-3110
DavidB-RTR-3110
FaizyTR-3110
OmarMC-102
ClaudeST-S1/4
ClaudeST-S1/4
ClaudeMC-110N
HardikTR-3110
ChrisTR-3110
DavidBTR-3110
FaizTR-3110
MC=MCENG ST=STBIO TR=TRENG
COMP-250 Weekly Schedule
Analysis of Algorithms
Analysis of Addition
{cst
{cst
{cst{linear
Time(N) = c1 + c2⨯N
Analysis of Multiplication
{cst
{cst
{cst{linear{quadratic
{quadraticAnalysis of Multiplication
{cst
{cst
cst{
linear{
{cst
{cst
Time(N) = c1 + c2⨯N + c3⨯N2
Analysis of Algorithms
Analysis of Algorithms
Time(N) = c1 + c2⨯N + c3⨯N2
Time(N) = c1 + c2⨯N
Multiplication
Addition
Analysis of Algorithms
Time(N) is O(N2)
Time(N) is O(N)
Multiplication
Addition
Analysis of Algorithms
Multiplication
Addition
UnaryRepresentation
Decimal/binaryRepresentation
50x x2 2x
Today, the best known Multiplicationalgorithm has running time
O(N⨯2log* N) barely slower than Addition… ( log* N = number of log until < 1 )
Analysis of Algorithms
Addition
50x x2 2x
MultiplicationMultiplicationMultiplicationMultiplication
Multiplication
Bases and Binary Representation
Base 8 vs Base 2
=(????)2
(2143)8
=( 010 001 100 101 )2 =(10001100101)2
(2143)8
Base 8 vs Base 2
(10010010101010101)2 =(10 010 010 101 010 101)2
=(2 2 2 5 2 5)8 =(222525)8
Base 2 vs Base 8
(10010010101010101)2 =(65536+8192+1024+256+64+16+4+1)10
=(75093)10
Base 2 vs Base 10
20=1 21=2 22=4 23=8 24=16 25=32 26=64 27=128 28=256 29=512 210=1024 211=2048 212=4096 213=8192 214=16384 215=32768 216=65536 232 = 4 294 967 296
Powers of 2 in Base 10
100=1 101=1010 102=1100110 103=1111101000 ≈210 104=10011100010000
Powers of 10 in Base 2
(75093)10 =(111*10011100010000 .
+101*1111101000 . +1001*1010 .
+101)2 =(10010010101010101)2
Base 10 vs Base 2
to Base 2
75093 /2 %2 37546 1 18773 0 9386 1 4693 0 2346 1 1173 0 586 1 293 0 146 1
/2 %2 73 0 36 1 18 0 9 0 4 1 2 0 1 0 0 1
=(10010010101010101)2
why does it work ?
m = 2* (m/2) + m%2
10010010101010101 = 2*1001001010101010 + 1
m = 𝛃* (m/𝛃) + m%𝛃
why does it work ?m = ∑i
n=-01 bi𝛃i
= (bn-1bn-2…b1b0)𝛃 = (bn-1bn-2…b10)𝛃 + b0 = 𝛃*(bn-1bn-2…b1)𝛃 + b0
= 𝛃*(bn-1bn-2…b1b0/𝛃) + b0 m = 𝛃* (m/𝛃) + m%𝛃
to Base 2
𝛃
𝛃𝛃
𝛃
75093 /5 %5 15018 3 3003 3 600 3 120 0 24 0 4 4 0 4
=(4400333)5
Winter 2016COMP-250: Introduction
to Computer ScienceLecture 3, January 19, 2016