Professional Documents
Culture Documents
01 Introduction
01 Introduction
Prof. J. Elder
Textbooks
• Required Text:
– Cormen, T.H., Leiserson, C.E., Rivest, R.L. & Stein, C. (2001).
Introduction to Algorithms, 2nd Ed. Cambridge, Mass: MIT
Press.
• Available in the York University Bookstore
• Also available from www.amazon.ca for $68.01
• Optional Text:
– Edmonds, J. How to Think about Algorithms. New York, NY:
Cambridge University Press.
• You will learn best if you try to tackle each problem by yourself
initially.
• You are encouraged to discuss the problems and work in groups to
overcome roadblocks.
• You are encouraged to team up with a partner and write up a single
assignment report (maximum 2 per group).
• Make the reports as concise and organized as possible. Marks may
be taken off for excess verbosity or lack of clarity.
• Late assignments are not excepted (except for medical emergencies
– please see syllabus).
• These slides:
– are available from the website
www.elderlab.yorku.ca/~elder/teaching/cse3101
– may change up to the last minute as I polish the lecture.
– Include slides originally created by J. Edmonds: Thanks Jeff!
• A list of algorithms.
– Learn their code.
– Trace them until you are convinced that they work.
– Implement them.
class InsertionSortAlgorithm extends SortAlgorithm
– Worry about details. {
void sort(int a[]) throws Exception {
for (int i = 1; i < a.length; i++) {
int j = i;
int B = a[i];
while ((j > 0) && (a[j-1] > B)) {
a[j] = a[j-1];
j--; }
a[j] = B;
COSC 3101, PROF. J. ELDER 9 }}
Innovation
Abraham Lincoln
Thomas Edison
For example . . .
Classifying Functions
f(i) = nΘ(n)
Time Complexity
t(n) = Θ(n2)
Time
Input Size
<preCond>
1
codeA T+
0
loop 5 km
<loop-invariant> i-1 i
exit when <exit Cond>
codeB 9 km
codeC
<postCond>
i
i
One step
Code Relay Race
at a time
2 8 9 5 8
4 4 4 6 2 3
5 3 5 7 5 6 1
2 3 2 5 4 8
•Ask questions.
• Why is it done this way and not that way?
Guesses and Counter Examples