Recurrences, Graphs,and MatricesProfessor Lucas BangHarvey Mudd CollegeDepartment of Computer Science
OverviewRecurrencesGraphsMatrices
3 powerful mathematical tools
1 super tool
Matrices Graphs
Recurrences
Sequences
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .2, 4, 6, 8, 10, 12, 14, 16, 18, 20, . . .
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .2, 4, 6, 8, 10, 12, 14, 16, 18, 20, . . .1, 2, 4, 8, 16, 32, 64, 128, 256, 512, . . .
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .2, 4, 6, 8, 10, 12, 14, 16, 18, 20, . . .1, 2, 4, 8, 16, 32, 64, 128, 256, 512, . . .2, 3, 5, 7, 11, 13, 17, 19, 23 . . .
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .2, 4, 6, 8, 10, 12, 14, 16, 18, 20, . . .1, 2, 4, 8, 16, 32, 64, 128, 256, 512, . . .2, 3, 5, 7, 11, 13, 17, 19, 23 . . .1, 3, 6, 10, 15, 21, 28, 36, . . .
Sequences111211211111221312211131122211113213211
Sequences111211211111221312211131122211113213211
one one
Sequences111211211111221312211131122211113213211
one one
Sequences111211211111221312211131122211113213211
one onetwo ones
Sequences111211211111221312211131122211113213211
one onetwo ones
Sequences111211211111221312211131122211113213211
one onetwo onesone two, one one
Sequences111211211111221312211131122211113213211
one onetwo onesone two, one one
Sequences111211211111221312211131122211113213211
one onetwo onesone two, one oneone one, one two, two ones
Sequences111211211111221312211131122211113213211
one onetwo onesone two, one oneone one, one two, two onesthree ones, two twos, one one
Sequences111211211111221312211131122211113213211
one onetwo onesone two, one oneone one, one two, two onesthree ones, two twos, one one
Conway’s Look-and-Say Sequence
Sequences
Neil Sloane Sloan’s Notebook
Sequences
Sequences
Sequencesordered lists of numbers1, 1, 1, 1, 1, 1, 1, 1, 1, 1, . . .1, 2, 3, 4, 5, 6, 7, 8, 9, 10, . . .2, 4, 6, 8, 10, 12, 14, 16, 18, 20, . . .1, 2, 4, 8, 16, 32, 64, 128, 256, 512, . . .2, 3, 5, 7, 11, 13, 17, 19, 23 . . .1, 3, 6, 10, 15, 21, 28, 35, . . .
Starting from any number, nIf n is even, compute n2If n is odd, compute 3n + 1Repeat
Collatz Sequences
Starting from any number, nIf n is even, compute n2If n is odd, compute 3n + 1Repeat35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, . . .
Collatz Sequences
Starting from any number, nIf n is even, compute n2If n is odd, compute 3n + 1Repeat35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, . . .
Try this out, starting withn = your age
Collatz Sequences
Collatz SequencesCollatz’s Conjecture: starting from anynumber, the pattern always reaches therepeating sequence . . . , 4, 2, 1, . . .
Collatz SequencesCollatz’s Conjecture: starting from anynumber, the pattern always reaches therepeating sequence . . . , 4, 2, 1, . . .
Q: Is it true?
Collatz SequencesCollatz’s Conjecture: starting from anynumber, the pattern always reaches therepeating sequence . . . , 4, 2, 1, . . .
Q: Is it true?A: Nobody knows!
Recurrences
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base case
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base casea1 = a0 + 2 = 0 + 2 = 2
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base casea1 = a0 + 2 = 0 + 2 = 2a2 = a1 + 2 = 2 + 2 = 4
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base casea1 = a0 + 2 = 0 + 2 = 2a2 = a1 + 2 = 2 + 2 = 4a3 = a2 + 2 = 4 + 2 = 6
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base casea1 = a0 + 2 = 0 + 2 = 2a2 = a1 + 2 = 2 + 2 = 4a3 = a2 + 2 = 4 + 2 = 6
In general,an = an−1 + 2
Recurrencessequence numbers computed from earlier valuesa0 = 0a1 = 2a2 = 4a3 = 6a4 = 8a5 = 10a6 = 12
a0 = 0base casea1 = a0 + 2 = 0 + 2 = 2a2 = a1 + 2 = 2 + 2 = 4a3 = a2 + 2 = 4 + 2 = 6
In general,an = an−1 + 2recurrence
Recurrencessequence numbers computed from earlier valuesa0 = 1a1 = 3a2 = 5a3 = 7a4 = 9a5 = 11a6 = 13
a0 = 1base casea1 = a0 + 2a2 = a1 + 2a3 = a2 + 2
an = an−1 + 2recurrence
Recurrencessequence numbers computed from earlier valuesa0 = 1a1 = 3a2 = 5a3 = 7a4 = 9a5 = 11a6 = 13
a0 = 1base casea1 = a0 + 2a2 = a1 + 2a3 = a2 + 2
an = an−1 + 2recurrence
Recurrencessequence numbers computed from earlier valuesa0 = 1a1 = 2a2 = 4a3 = 8a4 = 16a5 = 32a6 = 64
a0 = 1base casea1 = a0 × 2a2 = a1 × 2a3 = a2 × 2
an = an−1 × 2recurrence
Recurrencessequence numbers computed from earlier valuesa0 = 1a1 = 2a2 = 4a3 = 8a4 = 16a5 = 32a6 = 64
a0 = 1base casea1 = a0 × 2a2 = a1 × 2a3 = a2 × 2
an = an−1 × 2recurrence
RecurrencesFibonacci NumbersF0 = 1F1 = 1F2 = 2F3 = 3F4 = 5F5 = 8F6 = 13
F0 = 1base casesF1 = 1F2 = F1 + F0F3 = F2 + F1
Fn = Fn−1 + Fn−2recurrence
F4 = F3 + F2
RecurrencesFibonacci NumbersF0 = 1F1 = 1F2 = 2F3 = 3F4 = 5F5 = 8F6 = 13
F0 = 1base casesF1 = 1F2 = F1 + F0F3 = F2 + F1
Fn = Fn−1 + Fn−2recurrence
F4 = F3 + F2
RecurrencesLucas numbersL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7L5 = 11L6 = 18
L0 = 2base casesL1 = 1
Fn = Fn−1 + Fn−2recurrence
Recurrencesmake up your own base casesQ0 =?base casesQ1 =?Qn = Qn−1 + Qn−2recurrence
Compute the first 10 values
RecurrencesLucas numbers ratiosL0 = 2L1 = 1
RecurrencesLucas numbers ratiosL0 = 2L1 = 1 1 ÷ 2 = 0.5
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3
1 ÷ 2 = 0.53 ÷ 1 = 3
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.3333
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.33337 ÷ 4 = 1.75
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7L5 = 11
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.33337 ÷ 4 = 1.7511 ÷ 7 = 1.5714
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7L5 = 11L6 = 18
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.33337 ÷ 4 = 1.7511 ÷ 7 = 1.571418 ÷ 11 = 1.6364
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7L5 = 11L6 = 18
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.33337 ÷ 4 = 1.7511 ÷ 7 = 1.571418 ÷ 11 = 1.6364Try this for your sequence
RecurrencesLucas numbers ratiosL0 = 2L1 = 1L2 = 3L3 = 4L4 = 7L5 = 11L6 = 18
1 ÷ 2 = 0.53 ÷ 1 = 34 ÷ 3 = 1.33337 ÷ 4 = 1.7511 ÷ 7 = 1.571418 ÷ 11 = 1.6364Try this for your sequence
Matrices
[6 8 44 1 3]
Matricesrectangular arrangements of numbers
[6 8 44 1 3]
Matricesrectangular arrangements of numbers3 columns2 rows
[3 12 7]
Matricesrectangular arrangements of numbers2 columns2 rows
Matricesrectangular arrangements of numbers
[3 12 7] + [8 23 2
] =adding two matrices[? ?? ?
]
Matricesrectangular arrangements of numbers
[3 12 7] + [8 23 2
] =adding two matrices[11 35 9
]add entries in the same positions
Matricesrectangular arrangements of numbers
[3 12 7] + [8 23 2
] =adding two matrices[11 35 9
]add entries in the same positions
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[? ?? ?
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]?
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]3 × 2 + 1 × 0 = 6
?
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]3 × 1 + 1 × 4 = 7
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]3 × 1 + 1 × 4 = 7
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[2 10 4
] =multiplying two matrices[6 74 30
]
Matricesrectangular arrangements of numbers
[3 12 7]
×[37
] =multiplying a matrix by a single column matrix[1455
]
Matricesrectangular arrangements of numbers
[1 11 0]
×[10
] =multiplying a matrix by a single column matrix[11
]
Matricesrectangular arrangements of numbers
[1 11 0]
×[11
] =multiplying a matrix by a single column matrix[21
]
Graphs
123
4
Bridges of KönigsbergGraphs
123
4
Bridges of KönigsbergGraphs
123
4
Bridges of KönigsbergGraphs$1 $1 $1
$1$1$1$1
123
4
Bridges of KönigsbergGraphs$1 $1 $1
$1$1$1$1
Q: Starting from the north bank, how manydifferent bridge tours can I take for $4? (and I amhappy to see the same bridge more than once!)
Directed Graphsnodes connected by directed edges123
4
Directed Graphsnodes connected by directed edges123
4
$1 trips1 21 4
$2 trips1 21 2 131 2 41 4 3Q: how many $3 trips are there?
Directed Graphsnodes connected by directed edges123
4$2 trips1 21 2 131 2 41 4 3
1 2 11 2 1 24$3 trips
1 2 31 2 4 231 4 3 2
$2 trips1 21 2 131 2 41 4 3
1 2 11 2 1 24$3 trips
1 2 31 2 4 231 4 3 2
$1 trips1 21 4
$# 1 2 3 4 52 4 5 ? ?Homework: Fill in 4 and 5. What insights doyou have? Is there any pattern to discover?
Directed Graphsnodes connected by directed edges
1 2A slight variation: how many tripsthat cost $n start and end at 1?
Matrices and Graphs[1 11 0
]1 2
123
4
Matrices and Graphs
What does the matrix look like for the Königsberg graph?
Review
Matrices Graphs
Recurrences
[1 11 0] 1 2
Fn = Fn−1 + Fn−2
Review
Matrices Graphs
Recurrences
[1 11 0] 1 2
Fn = Fn−1 + Fn−2
Want to explore more?
These slides at www.cs.hmc.edu/∼bang