Admin Matters
Unit 3: Functions
Unit 4: Types
ssh
into on PE environmentsvim
tutorialsvim
?vim
, Exercise 0The range of a given list of k integers is the difference between the max and the min values in the list.
Give an algorithm to find the range given a list L of k integers.
Assume len(L) returns the size of the list.
\sqrt{\frac{\sum_{i=0}^{k-1}(l_i - \mu)^2}{k}}
\sqrt{\frac{\sum_{i=0}^{k-1}(l_i - \mu)^2}{k}}
\sum_{i=0}^{k-1}(l_i - \mu)^2
set \mu to mean(L)
set L' to subtract(L, \mu)
set L'' to square(L')
set total to sum(L'')
\sum_{i=0}^{k-1}(l_i - \mu)^2
sum(square(subtract(L, mean(L))))
\frac{\sum_{i=0}^{k-1}(l_i - \mu)^2}{k}
mean(square(subtract(L, mean(L))))
\sqrt\frac{\sum_{i=0}^{k-1}(l_i - \mu)^2}{k}
sqrt(mean(square(subtract(L,mean(L)))))
5 9 81 3 2
12 20 11 20 14 2 24 36 43 16 27 6 11 7 10 15 38 10 22 7 16 26 32 30 11 9 30 6 20 6 27 19 26 10 27 6 19 34 5 9 3 2210 4 13 1 10 22 43 36 39 29 41 12 13 2517 8 30 31 29 38 2 42 7 45 24 33 9 4034 29 37 2 26 17 19 34 6 7 34 22 21 4138 5 15 13 9 1 42 39 5 29 38 4 22 2941 10 26 32 30 26 16 16 18 22 32 34 14 105 17 25 16 19 6 31 16 3 13 8 42 41 0 13 30 44 1 41 14 5 39 40 38 6 37 38 9 .
12
to the maximum among 20 11 20 14 2 24 36 43 16 27 6 11 7 10 15 38 10 22 7 16 26 32 30 11 9 30 6 20 6 27 19 26 10 27 6 19 34 5 9 3 2210 4 13 1 10 22 43 36 39 29 41 12 13 2517 8 30 31 29 38 2 42 7 45 24 33 9 4034 29 37 2 26 17 19 34 6 7 34 22 21 4138 5 15 13 9 1 42 39 5 29 38 4 22 2941 10 26 32 30 26 16 16 18 22 32 34 14 105 17 25 16 19 6 31 16 3 13 8 42 41 0 13 30 44 1 41 14 5 39 40 38 6 37 38 9 .
We know how to find max(L,k) for smaller k
12 20 11 20 14 2 24 36 43 16 27 6 11 7 10 15 38 10 22 7 16 26 32 30 11 9 30 6 20 6 27 19 26 10 27 6 19 34 5 9 3 2210 4 13 1 10 22 43 36 39 29 41 12 13 2517 8 30 31 29 38 2 42 7 45 24 33 9 4034 29 37 2 26 17 19 34 6 7 34 22 21 4138 5 15 13 9 1 42 39 5 29 38 4 22 2941 10 26 32 30 26 16 16 18 22 32 34 14 105 17 25 16 19 6 31 16 3 13 8 42 41 0 13 30 44 1 41 14 5 39 40 38 6 37 38 9 .
We know how to find max(L,k) for smaller k
12 20 11 20 14 2 24 10 15 38 10 22 7 16 20 6 27 19 26 10 27 10 4 13 1 10 22 43 17 8 30 31 29 38 2 34 29 37 2 26 17 19 38 5 15 13 9 1 42 41 10 26 32 30 26 16 5 17 25 16 19 6 31 13 30 44 1 41 14 5 .
36 43 16 27 6 11 7 26 32 30 11 9 30 6 6 19 34 5 9 3 22 36 39 29 41 12 13 25 42 7 45 24 33 9 40 34 6 7 34 22 21 41 39 5 29 38 4 22 29 16 18 22 32 34 14 10 16 3 13 8 42 41 0 39 40 38 6 37 38 9 .
where n = \left\lfloor\frac{i+j}{2}\right\rfloor
n! = n \times n-1 \times \ldots \times 2 \times 1
n! = n \times (n-1)!
Special case: 0! = 1
1010010101010101001111010..
can meanhello
1
or 0
black or white
true or false
yes or no
S or U
11
, 10
, 01
, or 00
north, south, east, west
spring, summer, fall, winter
0 to 255 (for unsigned)
-128 to 127 (for signed)
-9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
0-9, A-Z, a-z<>?:”{}!@#$%^&*()_+-=[]\';/.,
return, tab, escape, etc
11111011000000000 😀
(also called floating point numbers)
E.g., 0.1 + 0.2
is 0.30000000000000004
set total to sum(L, k)
set avg to mean(L, k)
k is an integer
total is an integer
avg must be a real number
ssh
into CS1010 PE hosts and follow the Unix CLI and vim
tutorialVersion: 1.1
Last Updated: Tue Aug 18 12:24:32 +08 2020
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |