Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active August 14, 2019 00:49
Show Gist options
  • Select an option

  • Save harrisonmalone/eb4d72d3d0ec4eb51f506fd82e7dadf6 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/eb4d72d3d0ec4eb51f506fd82e7dadf6 to your computer and use it in GitHub Desktop.

Math topic master list

Bases

Counting in different bases

  1. If you were to count in base 8, what would the next three numbers be?
1, 2, 3, 4, 5, 6, _, _, _
  1. If you were to count in base 14, what would the next three numbers be?
1, 2, 3, 4, 5, 6, 7, 8, 9, _, _, _
  1. If you were to count in base 5, what would the next three numbers be?
3, 4, _, _, _
  1. If you were to count in base 15, what would the next three numbers be?
A, B, C, D, E, _, _, _
  1. What are the next 9 numbers after 3 in base 4?

  2. What are the next 9 numbers after 8 in base 13?

Binary to hex

  1. Convert 10011001 to hexadecimal.

  2. Convert 10011101 to hexadecimal.

  3. Convert 11011011 to hexadecimal.

  4. Convert 010111110001 to hexadecimal.

Binary to decimal

  1. Convert 10011001 to decimal.

  2. Convert 10001101 to decimal.

  3. Convert 110010011001 to decimal.

  4. Convert 1001100110101111 to decimal.

One base to another

  1. Convert 138 to hexadecimal.

  2. Convert 3610 to base 7.

  3. Convert 2411 to base 5.

  4. Convert 123 to base 9.

  5. Convert 2267 to base 13.

Hex to decimal

  1. Convert 2A16 to decimal.

  2. Convert 55516 to decimal.

  3. Given the hex color #5f1f6c, write what the values of each R, G, and B would be in base 10.

  4. Given the hex color #221BFF, write what the values of each R, G, and B would be in base 10.

Pseudocode decimal to binary

  1. Given any decimal number write some pseudocode inside of a ruby method that describes the way in which you'd convert the decimal to binary using only ruby. You cannot use built in ruby methods like to_s.

Writing code to convert decimal to any base

  1. Write a method that will convert any base 10 integer passed as an argument to binary without using any built in ruby functions like to_s

  2. Write a method that will convert any base 10 integer passed as an argument to Base 8 without using any built in ruby functions like to_s

  3. Write a method that will convert any base 10 integer passed as the first argument to a base specified as the second argument without using any built in ruby functions like to_s

Logic

Truth tables

  1. Fill in the ∧ (AND) truth table.
A B A ∧ B
0 0
0 1
1 0
1 1
  1. Fill in the ∨ (OR) truth table.
A B A ∨ B
0 0
0 1
1 0
1 1

The βŠ• symbol represents an XOR in truth tables and bitwise operations (and it is the symmetric difference in set theory, which is different).

  1. Fill in the βŠ• (XOR) truth table.
A B A βŠ• B
0 0
0 1
1 0
1 1

Bitwise operations

  1. 1100 ∧ 0111 = ?

  2. 1100 ∨ 0111 = ?

  3. 1100 βŠ• 0111 = ?

  4. 0101 ∧ 1001 = ?

  5. Β¬0110 = ?

Transposition then bitwise

Answer the following questions as decimal.

  1. 910 ∧ 1010 = ?

  2. 910 ∨ 1010 = ?

  3. 910 βŠ• 810 = ?

  4. 1210 ∧ 1010 = ?

  5. 7510 βŠ• 3210 = ?

  6. 32110 βŠ• 9710 = ?

Answer the following questions as hexadecimal.

  1. F316 βŠ• 316 = ?

  2. A216 ∧ 3116 = ?

Transpose and bitwise shift

  1. 0110 << 2 OR 1100 >> 2 = ?

  2. 1111 << 1 OR 1100 >> 2 = ?

  3. 17 << 2 AND 90 >> 1 = ?

  4. 65 << 4 OR 36 >> 2 = ?

Writing a logical statement from real world situations

A = "you are older than 13" 
B = "you are with your parents" 
C = "you can attend a PG-13 movie" 
  1. Given the variables above write a logic statement to represent "if you are older than 13 or you are with your parents then you can attend a PG-13 movie".
B = "I like football"
W = "I am going to watch a game"
S = "today is Saturday"
F = "football is on today"
  1. Given the variables above write a logic statement which would evaluate to true if all of the above conditions are true.

Sets

Set operations

For the next few questions write out the resultant set.

A = {2,4,6} 
B = {3,6,9}
  1. B - A = ?
C = {4,6,8} 
D = {7,8,9}
  1. C βˆͺ D = ?
E = {7,8,1} 
F = {1,3,5}
  1. E ∩ F = ?
G = {2, 3, 7, 8, 9}
H = {2, 8}
I = {4, 6, 7, 10}
  1. G βˆͺ I - H = ?

Sets and domains

A = {2,3,7,4,1,8,9}
  1. Given A what is {π‘₯ | x ∈ A; π‘₯ > 0; π‘₯ ≀ 4}?

  2. Given A what is {π‘₯ | x ∈ A; π‘₯ > 2; π‘₯ ≀ 3}?

  3. Given A what is {π‘₯ | x ∈ A; π‘₯ β‰₯ 7; π‘₯ < 10}?

  4. Given A what is {π‘₯ | x ∈ A; π‘₯ β‰₯ 6; π‘₯ ≀ 8}?

  5. {π‘₯ | π‘₯ ∈ β„•, π‘₯ > 2 ∧ π‘₯ < 8}

  6. {π‘₯ | π‘₯ ∈ β„•, π‘₯ > 3 ∧ π‘₯ < 7}

Combining the set operations to make symmetric difference

A = {1,2,3}	
B = {3,4,5}	
  1. A βŠ• B = ?
C = {2, 3, 7, 8, 9}
D = {2, 8}
E = {4, 6, 7, 10}
  1. C βŠ• E - D = ?
F = {b,g,w,h,k,a}
G = {w,a,k,e,y}
  1. F βˆͺ G βˆ’ F ∩ G = ?

  2. F βŠ• G = ?

Sets and modulus

  1. {π‘₯ | π‘₯βˆˆβ„•; π‘₯ mod 5 = 0 ∧ x < 25}

  2. {π‘₯ | π‘₯βˆˆβ„•; π‘₯ mod 10 = 0 ∧ x ≀ 70}

Complement of a set

  1. Given a set of Coder Academy students that study in Melbourne, and a domain of all the students across all Coder Academy campuses (Melbourne, Sydney, Brisbane), what is the complement of the Coder Academy students in Melbourne?

  2. Given a set of players in the AFL who've played over 100 games, and a domain of all players in the AFL, what is the complement the set of players who've played over 100 games?

A = {1,2,3,4}
B = {1,2,3,4,5}
  1. Given a set A, and the domain of B, what is the complement of A?

Big O

Which is faster between Big O values

  1. Order the following time complexities from fastest to slowest
  • O(1)
  • O(n log n)
  • O(n^2)
  • O(n)
  • O(log n)
  • O(2^n)

Binary search vs linear

You're asked to guess a number between 1 and 50 that your teacher is thinking of.

  1. What's the maximum possible guesses it would take to find this number using linear search? Whats the time complexity?

  2. What's the maximum possible guesses it would take to find this number using binary search? Whats the time complexity?

Optimizing algorithms

  1. There is a set A of n numbers that are unsorted. There is a set B of n numbers that are unsorted. You want to write a function to merge these two sets together to ensure that you return one sorted set. Is there a faster way than O(n2)? If so, describe how it would work and what the Big O would achieve?

For the following questions you're in this real life situation: you are given a phone book (like the yellow pages), the phone book has businesses which have unique names. The names are sorted by alphabetical order.

  1. Your boss tells you to find the phone number of "Coder Academy". They say the phone number is on page 102. Is there a faster way to find the phone number than O(n)? If so, describe how it would work?

  2. Your boss tells you to find "Coder Academy" again but this time you're just given the business name. Is there a faster way to find the phone number than O(log n)? If so, describe how it would work?

Judging the algorithm of some code

  1. What is the time complexity of the following code in Big O?
def get_last(items)
  items[items.length - 1]
end 
  1. What is the time complexity of the following code in Big O?
def find_index(items, match)
  index = 0
  while index < items.length - 1
    if items[index] == match
     return index
    end 
    index += 1
  end 
  return -1 
end 
  1. What is the time complexity of the following code in Big O?
def build_square_matrix(items)
  matrix = []
  index_one = 0
  index_two = 0
  while indexOne < items.length - 1
    matrix[indexOne] = []
    indexOne += 1
    while indexTwo < items.length - 1
      matrix[indexOne].push(items[indexTwo])
      indexTwo += 1
    end 
  end 
  return matrix 
end

Optimizing code

  1. If you were to make a change to improve the code, what change would you make? What would be the time complexity after the change?
def find_num_in_array(num, arr)
  found_num = nil
  arr.each do |item|
    if item == num
      found_num = item
    end
  end 
  if !found_num
    return 'num not in array'
  else 
    return found_num
  end 
end

result = find_num_in_array(1, [3, 1, 5])
  1. If you were to make a change to improve the code, what change would you make? What would be the time complexity after the change?
def is_num_in_array(num, arr)
  middle_index = arr.length / 2
  if arr[middle_index] == num 
    return true
  end 
  if middle_index == 0 
    if num == arr[middle_index]
      return true
    else 
      return false
    end 
  end 
  if num < arr[middle_index]
    arr.slice!(middle_index..(arr.length - 1))
  else 
    arr.slice!(0..middle_index)
  end 
  is_num_in_array(num, arr)
end

result = is_num_in_array(4, [1,2,3,4,5,6])
  1. If you were to make a change to improve the code, what change would you make? What would be the time complexity after the change?
arr_of_arrays = [
  [1,2,3,4],
  [5,6,7,8]
]

def is_num_in_arrays(passed_int, arr_of_arrays)
  arr_of_arrays.each do |array|
    array.each do |int|
      if int == passed_int
        return true
      end 
    end
  end 
  return false
end 

result = is_num_in_arrays(7, arr_of_arrays)

Matrices

Scalar matrix multiplication

A = [[2,4],[3,6]]
  1. What is 5A?
B = [[3,4],[2,1]]
  1. What is 2B?

Matrix subtraction and addition

  1. Follow the instructions below.

Given:

A = [[2,4],[3,6]]
B = [[1,2],[3,4]]
  • a. What is A + B?
  • b. What is A - B?

Matrix dot product

  • c. What is A Γ— B?
  1. What is C Γ— D, given the following?
C = [[1,2,3], [4,5,6]]
D = [[7,8],[9,10],[11,12]]
  1. What is E Γ— F, given the following?
E = [[3,4,2]]
F = [[13,9,7,15], [8,7,4,6], [6,4,0,3]]

Matrix transpositions

  1. Given the following:
A = [[2,4],[3,6]]
B = [[1,2],[3,4]]

What is AT x B?

  1. Given:
X = [[3,4],[2,1]]

a. What is X βˆ’ XT?

b. What is X Γ— XT?

Graphs

Identifying graphs

  1. What type of graph this?

  1. What type of graph is this?

Shortest paths across nodes

  1. Find the shortest path across all nodes.

  1. Find the shortest path across all nodes.

  1. Find the shortest path across all nodes.

Graph to edge list

  1. Convert the following graph to an edge list.

  1. Convert the following graph to an edge list.

Matrix to graph

  1. Convert the following matrix to a graph.

  1. What type of graph this?

  2. Find the shortest path starting at A and ending at E.

  3. Convert the following matrix to a graph. You'll have nodes from G0 to G8.

  1. Find the shortest path between G0 and G8

Matrix to edge list

  1. Convert the following matrix to an edge list.

  1. Using either the edge list or the matrix draw a graph.

  2. Find the shortest path starting at E and ending at S.

Shortest path from graph

  1. Draw out the graph for:
(S,5,A),(S,2,B),(A,4,C),(B,8,A),(C,6,D),(A,2,D),(C,3,F),(D,1,F)
  1. Find the shortest path from S to F in the graph?

  2. Find the shortest path from A to Z.

  1. Find the shortest path from A to Z.

Functions and relations

Sum of and functions

  1. Given the following equation and domain, what is the sum? Note that to view the sum symbol correctly you need to be using Safari or Chrome.
           4
f(X) = ⎲ xi2
       ⎳
          i=0
X = [4, 7, 9, 2, 1]

Defining sets of numbers as a relation

  1. Given the following information, which relations (pairs) are in A?
{ (x, y) Ο΅ A | x β‰₯ y }
X = [(1,2), (2,2), (20, 21), (21, 20)]
  1. What type is the relation above (reflexive, symmetric, transitive)?

  2. Given the following information, which relations (pairs) are in T?

{ (x,y) Ο΅ T | x Ο΅ β„•; y Ο΅ β„•; y β‰₯ 6x + 1 }
X = {(2,7), (3,1), (3,0), (10,101), (4,6)}
  1. Given the following information, which relations (pairs) are in D?
{ (x,y) Ο΅ D | x Ο΅ β„•; y Ο΅ β„•; y β‰₯ 20; x < 10 }
X = {(1,1), (29,10), (10,10), (9,20)}

Real world relations

  1. State a real world example for reflexivity, symmetry, and transitivity.

  2. Is "sibling" a reflexive relation? Explain.

  3. What type of relation is it (for sibling)?

Domain and range

nums = [-2, 0, 1, 2]
  1. Given this equation f(x) x2 + 5, if we're mapping nums over f(x), what are the elements in the domain?

  2. Given this equation f(x) x2 + 5, if we're mapping nums over f(x), what are the elements in the range?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment