CS 213 M: Introduction: Abhiram Ranade
CS 213 M: Introduction: Abhiram Ranade
CS 213 M: Introduction: Abhiram Ranade
Abhiram Ranade
January 7, 2019
Syllabus
For the most part you will be expected to write C++ code;
Pseudocode not allowed.
You are more fluent in C++ than in English
You will be allowed to bring one book to all exams.
When you write a program you will have to argue that it is correct
I To your boss..
I To your teacher/TAs..
I To your programmer collegues..
I To yourself!
How do we argue that a program is correct?
Based on what we know about C++, we can say that after execution
I variable i will have the sum of variables k,j
I No other variable will change in value.
while(m % n != 0){
int r = m % n;
m = n;
n = r;
}
cout << n << endl;
m = n’ > 0, n = m’ % n’ > 0.
So proved by induction.
Proof of Lemma 2 and Lemma 3
We often first think of the invariant and then design the code.
How many multiplications does this code do for computing 2ˆ57?
How does this compare to the standard method?
Exercise 3
Consider the execution of the gcd program with m, n given the values
of the kth and k+1th Fibonacci numbers. How many iterations will
this take?