Lab 07 - Compiling with Clang
Slides:
Exercise 4 Review
Dynamic Array
malloc()- memory allocationcalloc(n, m)- calculate the allocation. And it means allocate a memory space for n values, each of size m.
Null Pointer Check
If you don't do Null Pointer Check, you will be penalised in PE
7. Kendall
Use math to simplify the algorithm
For each i in permutation:
for each j before i:
if j > i:
count += 19. Subtract
An idea to ignore the leading zero is to use start print from the first nonzero element if the result is not 0.
Compiler
clang -I,-Istands for "include"
Multidimensional Arrays
Remember the way to allocate a 2-D array (with null pointer check)
If the contiguous memory method, the code below
for (long i = 1; i < m; i += 1)
{
matrix[i] = matrix[i - 1] + n;
}This will define the starting point for each row.
Due to array decay, the address of an array is the same as the address of its first element.
Big O
means f(x) is upper bounded by g(x). or , which means set of all functions which do not grow more slowly than f.
Include the trivial results about Big O calculation in the cheatsheet.
If you have two inputs
mandn, you should include both variables because they are independent.The real way to compare growth rate is to take the limit.
Selected Problems from Exercise 5
Last updated