Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active November 25, 2018 05:51
Show Gist options
  • Save harrisonmalone/e4027b0a3d2fa879d14215461bcc9a36 to your computer and use it in GitHub Desktop.
Save harrisonmalone/e4027b0a3d2fa879d14215461bcc9a36 to your computer and use it in GitHub Desktop.

Math practise

Some really nice resources for maths wre written up by Gretchen last week. It contains examples as well as questions which are answered below.

  1. What kind of graph is this?
directed because it has the arrows, unweighted because there's no numbers 
  1. Draw edge list and adjacency matrix.
edge list
AC, AD, BB, CD, DC, DA, DB

adjacency matrix
  ABCD
A 0011
B 0200
C 0001
D 1110
  1. What kind of graph is this?
undirected because there's no arrows, weighted because there's numbers between the lines
  1. Draw edge list and adjacency matrix.
edge list 
A5B, A2C, A3D, B4C, C1E

adjacency matrix 
 ABCDE
A 05230
B 00400
C 00001
D 00000
E 00000
  1. Properties of relations described as "=".
the properties of the relation described as "=" are symmetric, reflexive and transitive, has all three
  1. Properties of relations described as ">=".
the properties of the relation described as ">=" are reflexive and transitive 
  1. Properties of relations described as ">".
the properties of the relation described as ">" are transitive 
  1. Provide example of transitive relationship.
an example of a transitive relationship is the following: if john is taller than bill, and bill is taller than fred, then its a logical consequence that john is taller than fred
  1. Binary to hex.
1001 1000
8001 8000
9    8
=>98
0110 0111
6    7
=>67
1101 0110
13   6
D    6
=>D6
0011 0101
3    5
=>35

10) hex to binary
3C
3 12
=>0011 1100

D4
13 4
=>1101 0100

2D
2 13
=> 0010 1101

C3
12 3
=>1100 0011
  1. Hex to decimal.
16**1 16**0
16    1
 
3C
3  C
3  12
(16 * 3 = 48) + (1 * 12 = 12) = 60

D4
D  4
13 4
(16 * 13 = 208) + (1 * 4 = 4) = 212 

2D
2 D
2 13
(16 * 2 = 32) + (1 * 13 = 13) = 45

C3
12 3
(16 * 12 = 192) + (1 * 3 = 3) = 195
  1. Order of complexity in BigO from most complex to least.
O(n**2) => looping through two different arrays and comparing, lots of sums (quadratic)

O(n) => looping through one array and comparing it to a result "are you apple?", a fair few sums (linear)

O(log n) => sorting array and then going to middle, asking are you higher or lower than value, excluding values that return false to this every time, least amount of sums in the end (binary)
  1. Code to convert base 10 to base 2 in JavaScript.

  2. Binary to decimal.

11010110
(0 * 1 = 0) + (1 * 2 = 2) + (1 * 4 = 4) + (0 * 8 = 0) + (1 * 16 = 16) + (0 * 32 = 0) + (1 * 64 = 64) + (1 * 128 = 128) = 2 + 4 + 16 + 64 + 128 = 214
  1. bitwise operations
&11010001
 01110110
 --------
 01010000

|10110101
 10001001
 --------
 10111101

^10110111
 01001011
 --------
 11111100
  1. Draw an | truth table.
  T F
T|T T 
F|T F
  1. Draw an & truth table.
  T F
T|T F 
F|F F
  1. Draw an ^ truth table.
  T F
T|F T 
F|T F
  1. Given vowels as set A, given alphabet as domain, find the compliment.
compliment of A is all other alphabet characters that aren't vowels 
A = {1,2,3,4}
B = {2,3,6,9}
  1. What is the intersection of these sets (A ∩ B)?
it's the elements that belong to both sets 

{2,3}
  1. What is A - B (A \ B)
the difference of sets A and B is the set of all elements of A which do not belong to B 

{1,4}

For matrices, this is a great resource for remembering how it's row by column.

a = [1,4]
    [2,5]
    [3,6]
b = [7,8,9]
    [0,1,2]
  1. Multiply a * b.
First item (1 * 7 + 4 * 0 = 7)
Second item (1 * 8 + 4 * 1 = 12)
Third item (1 * 9 + 4 * 2 = 17)

[7, 12, 17]
[14, 21, 28]
[21, 30, 39]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment