EECS 281 Lecture 1
Proffice OH: 2632 BBB, check Google Calendar to make sure
T Th in Chrysler?
Required Texts:
- Intro to Algorithms
- C++ STL
Office Hours: http://eecs.help
Labs - Pre-lab work before lab section, worksheet at start of lab
Late submission/Midterm Regrades: [email protected]
- Midterm Regrades: write and compile/run code, send it to email
Projects - 21 days
C++14 Standard
CAEN Linux g++ (GCC) 5.1.0, might not compile here even if XCode compiles
Exams - MC and Code
Printing lectures before each class
- Before lecture - make questions
- After lecture - check over concepts for clarity, and check for added material
Project 1 specs are out - autograder will be up on weekend
GCC 5.1.0 is the not the default version on CAEN, check Project 0 Makefile to find how to gain access
Xcode, CAEN, emacs will be useful
Version control - Git (gitlab.eecs.umich.edu)
Plotting Tools - plot algorithm statistics
- Gnuplot, Excel, Matlab
READ the CLRS text to learn algorithms
Xcode debug, GDB debug - one line at a time
Valgrind debug - memory leaks
Profilers debug - what code the program is spending the most time in
//REQUIRES: in and out are arrays with size elements
//MODIFIES: out
//EFFECTS: out[i] = in[0] *...* in[i-1] *
// * in[i+1] *...* in[size-1]
// REALLY BAD
void f(int *out, const int *in, int size) {
// for loop to multiply a certain value of out
for (i = 0; i < size; ++i) {
out[i] = 1; // initialization
for (j = 0; j < size; ++j) {
if (i != j) {
out[i] = out[i]*in[j]
}
}
}
}
// MORE EFFICIENT
void f(int *out, const int *in, int size) {
// take total product once, then divide by value for each i in out
int product = 1;
for (int i = 0; i < size; ++i) {
product *= in[i];
}
for (int i = 0; i < size; ++i) {
if (in[i] != 0) { // maybe will fix divide by 0? double CHECK
out[i] = product / in[i];
}
}
}
Office Hours - attend early for conceptual questions (bring beforehand), after attend for code questions
Post-Lecture Reimplementation on XCode
// Lecture 1 Algorithm Exercise
void f(int *out, const int *in, int size) {
// take total product once, then divide by value for each i in out
int product = 1;
int zero_count = 0;
for (int i = 0; i < size; ++i) {
if (in[i] == 0) ++zero_count;
else product *= in[i];
}
for (int i = 0; i < size; ++i) {
if (zero_count == 0) out[i] = product / in[i];
else if (zero_count == size) out[i] = 0;
else if (in[i] == 0) {
out[i] = product;
}
else out[i] = 0;
cout << i << ": " << out[i] << endl; // test
}
}
int main() {
int size = 3;
int in[3] = {3,2,0};
int out[3];
f(out, in, size);
return 0;
}