Pre-requisite Review
Total marks: 155
Homework deadline on Gradescope (Go to gradescope.com > Log In > “School Credentials” > “Search for your school” > “University of Maine” > Login).
Submission method: There are separate assignments in gradescope: Prereq autograded and Prereq Manually Graded. Problems 1-3 are Autograded, rest are manually graded. For autograding you will have to submit the three files:

Resources for review:
Recursion (Section 4.10) of Kernighan and Ritchie
A 30-page review of Linear Algebra by Zico Kolter
Review vectors here
Probability: Khan Academy
Multi-variable calculus: Khan academy
Linear algebra: Gilbert Strang lectures
Problem 1: Factorial¶
(20 marks)
The factorial of a non-negative integer n , denoted by , is the product of all positive integers less than or equal to n . The factorial of n also equals the product of n with the next smaller factorial:
For example, The value of 0! is 1, according to the convention for an empty product.
Write a recursive C function to compute factorial of a natural number n. It should pass the test_factorial function 10 times. test_factorial function is given.
C programmers: download and edit the file test
Rename the file to test_factorial.c. Complete the function and submit the file as a separate file to Gradescope autograder.
Problem 2: Prime numbers¶
(20 marks)
A natural number (1, 2, 3, 4, 5, 6, etc.) is called a prime number (or a prime) if it is greater than 1 and cannot be written as the product of two smaller natural numbers.
Write a C function to calculate if a number is prime. Return 1 if it is prime and 0 if it is not a prime. If the number is not a prime number, then a factor exists. Return the factor as through a pointer.
C programmers: Download and edit the file test
Rename the file to test_prime.c. Complete the function and submit the file as a separate file to Gradescope autograder.
Problem 3: Structures¶
(20 marks)
2.a. Write a C data structure named struct date that capture year, month and days of a date.
2.b. Also write a function greg_is_leap_year that determines whether an year is a leap year.
2.c. Also write a function date_greg_days that count the total number of days since 0001-01-01 AD.
C programmers: Download and edit the file test
Rename the file to test_date.c. Complete the function and submit the file as a separate file to Gradescope autograder.
Problem 4: Probability and statistics¶
(25 marks)
Resources: Khan Academy
Write the definitions of a Random Variable, Expectation, and Variance. (5 marks)
What is the difference between Expectation and a sample mean? When do they converge? (5 marks)
What is the difference between Probability density function, a Probability mass function and Cumulative distribution function. (5 marks)
Prove that for any Random Variable , the variance , where denotes the expectation of . (5 marks)
Prove that (5 marks)
Problem 5: Multivariable Calculus¶
(20 marks)
Resources: Khan academy
Find the mininimum point the function using calculus. Write the property of derivatives that made you reach the answer? (10 marks)
Find the mininimum point the function using calculus. Write the property of derivatives that made you reach the answer? (10 marks)
Problem 6: Linear Algebra¶
(50 marks)
Please review Linear Algebra concepts and notations from here and answer the following questions (all answers are in the pdf).
Other resources: Gilbert Strang lectures
(2 marks) In matrix notation defined in the linked document, when I say a matrix is (alternatively the matrix is in the set , does the n refer to the number of rows or the number of columns .
(5 marks) Let the matrix and be defined as
Is the matrix multiplication valid? Make up an example of matrix when matrix multiplication would not have been valid. Find out the matrix multiplication by hand. Write down all the steps to show which numbers get multiplied by which numbers.
Given two matrices of size and of size , when is the matrix multiplication valid? When is the matrix multiplication valid? When is the addition valid? (5 marks)
What is the transpose of a matrix? If a matrix has the shape , what is the shape of matrix (3 marks).
Define dot product for two vectors? How to test when two given vectors are perpendicular? Assume you have two n-dimensional vectors and . Denote dot product as, ? (5 marks)
Denote the above vectors as column matrices. Define the following matrices with the vector components.
Use matrix operation like matrix transpose and matrix multiplication to write vector dot product (5 marks).
Define cross product for two vectors? How to test when two vectors are parallel to other? (5 marks)
How to can you find the magnitude of a vector? What is a unit vector? (5 marks)
What is a square matrix (0 marks)?
What are the column vectors and row vectors of a matrix? How can you write matrix multiplication in terms of row vectors and column vectors of a matrix (5 marks)?
Suppose you are given a square matrix called . All it’s columns vectors are unit vectors and every pair of the unit vectors are perpendicular to each other. Find out the product . What is the name of given to such matrices whose column vectors are unit vectors and are perpendicular to each other? (10 marks).
Hint
Assume the column vectors of the matrix be . Then the matrix can be written as,
The transpose of matrix is
Block multiply them together to find the answer. Also, see the Block matrix Multiplication