I start at 0 so that when we get to chapter 1, the numbering will agree with the text.
There is a web site for the course. You can find it from my home page.
The course text is Goodrich and Tamassia: ``Algorithm Design: Foundations, Analysis, and Internet Examples.
The major components of the grade will be the midterm, the final, and problem sets. I will post (soon) the weights for each.
We will have a midterm. As the time approaches we will vote in class for the exact date. Please do not schedule any trips during days when the class meets until the midterm date is scheduled.
If you had me for 202, you know that in systems courses I also assign labs. Basic algorithms is not a systems course; there are no labs. There are homeworks and problem sets, very few if any of these will require the computer. There is a distinction between homeworks and problem sets.
Problem sets are
I run a recitation session on tuesdays from 2-3:15. I believe there is another recitation section. You need attend only one.
Good methods for obtaining help include
I use the upper left board for homework assignments and announcements. I should never erase that board. Viewed as a file it is group readable (the group is those in the room), appendable by just me, and (re-)writable by no one. If you see me start to erase an announcement, let me know.
It is university policy that a student's request for an incomplete be granted only in exceptional circumstances and only if applied for in advance. Naturally, the application must be before the final exam.
We are interested in designing
algorithms (a step-by-step procedure for performing
some task in a finite amount of time) and
data structures (a systematic way of organizing and
Unlike v22.102, however, we wish to determine rigorously just how good our algorithms and data structures really are and whether significantly better algorithms are possible.
We will be primarily concerned with the speed (time complexity) of algorithms.
We will emphasize instead an analytic framework that is independent of input and hardware, and does not require an implementation. The disadvantage is that we can only estimate the time required.
Homework: R-1.1 and R-1.2 (Unless otherwise stated, homework problems are from the last section in the current book chapter.)
Designed for human understanding. Suppress unimportant details and describe some parts in natural language (English in this course).
The key difference between the RAM model and a real computer is the assumption of a very simple memory model: Accessing any memory element takes a constant amount of time. This ignores caching and paging for example. (It also assumes the word-size of a computer is large enough to hold any address, which is generally valid for modern-day computers, but was not always the case.)
The time required is simply a count of the primitive operations executed. There are several different possible sets of primitive operations. For this course we will use
Let's start with a simple algorithm (the book does a different simple algorithm, maximum).
Algorithm innerProduct Input: Non-negative integer n and two integer arrays A and B of size n. Output: The inner product of the two arrays. prod ← 0 for i ← 0 to n-1 do prod ← prod + A[i]*B[i] return prod
The total is thus 1+1+5n+2n+(n+1)+1 = 8n+4.
Homework: Perform a similar analysis for the following algorithm
Algorithm tripleProduct Input: Non-negative integer n and three integer arrays A. B, and C each of size n. Output: The A*B*C + ... + A[n-1]*B[n-1]*C[n-1] prod ← 0 for i ← 0 to n-1 do prod ← prod + A[i]*B[i]*C[i] return prodEnd of homework
Let's speed up innerProduct (a very little bit).
Algorithm innerProductBetter Input: Non-negative integer n and two integer arrays A and B of size n. Output: The inner product of the two arrays prod ← A*B for i ← 1 to n-1 do prod ← prod + A[i]*B[i] return prod
The cost is 4+1+5(n-1)+2(n-1)+n+1 = 8n-1
THIS ALGORITHM IS WRONG!!
If n=0, we access A and B, which do not exist. The original
version returns zero as the inner product of empty arrays, which is
arguably correct. The best fix is perhaps to change
Positive in the Input specification.
Let's call this algorithm innerProductBetterFixed.
What about if statements?
Algorithm countPositives Input: Non-negative integer n and an integer array A of size n. Output: The number of positive elements in A pos ← 0 for i ← 0 to n-1 do if A[i] > 0 then pos ← pos + 1 return pos
Let U be the number of updates done.
Consider a recursive version of innerProduct. If the arrays are of size 1, the answer is clearly AB. If n>1, we recursively get the inner product of the first n-1 terms and then add in the last term.
Algorithm innerProductRecursive Input: Positive integer n and two integer arrays A and B of size n. Output: The inner product of the two arrays if n=1 then return AB return innerProductRecursive(n-1,A,B) + A[n-1]B[n-1]
How many steps does the algorithm require? Let T(n) be the number of steps required.
Problem Set #1, Problem 1.
The problem set will be officially assigned a little later, but the first problem in the set is R-1.27.