text
stringlengths
2
10.6k
Keep a diary.
Send an email to somebody that you trust, addressed to them, and then walk away from it.
Because what you'll have is at the end of a year, you'll have a list of 250 things you did you weren't required to do.
And you did them just so you could see if there was something hinky or fraudulent or bad out there.
At the end of two or three years, you'll have a volume that you'll be able to show to somebody.
Because in this day and age, and it's an awful thing to have had happen, you frequently have to prove your innocence.
It used to be, no, you're innocent until proven guilty.
[ERRT]
No, just ask Martha Stewart.
That's not true anymore.
And especially in the court of public opinion, which, as I just mentioned, sometimes is a lot more important than what goes on in any courtroom.
Only you can do that to indemnify yourself.
Then if a fraud happens, if something happens, and a decision maker-- read that as a prosecutor or civil
litigant-- has to go, I'm either going to lean this way on this person or I'm going to lean that way, they will always lean in your favor.
Because they'll go, I've seen what kind of person this guy is.
This is a guy who goes the extra mile, who really looks for this.
Welcome to this first course in the design and analysis of algorithms.
I imagine many of you are already clear on your reasons for taking this course, but let me begin by justifying the course's existence.
I'm giving you several different motivations for learning about algorithms.
So, what is an algorithm?
Well, we're not going to be needing a precise definition in this course, but essentially, an algorithm is a well-defined set of rules.
A recipe in effect for solving some kind of computational problem.
So, for example, maybe you're given a bunch of numbers and you want to rearrange them into sorted order.
Maybe you're given a road network with an origin and a destination, and you want to compute the shortest path from point a to point b.
Maybe you're given a bunch of tasks with deadlines and you want to know weather or not it's feasible to accomplish all of those tasks by their respective deadlines.
So, why study algorithms?
Well, first of all, understanding the field of algorithms, and also the related field of data structures, is crucial for doing serious work in pretty much any other branch of Computer
Science.
That's the precise reason why here at Stanford University, this is the course that's required for all of the degrees that the Computer Science
Department grants, be it a Bachelors, a Masters, or a PhD degree, we insist that you have mastery of the field of algorithms.
So, what are some examples of uses in the rest of Computer Science?
Well, if you're doing routing and communication network, that piggybacks on classical shortest path algorithms.
the effectiveness of public key cryptography really rests on that, of number theoretic algorithms.
In, say, computer graphics, you need the computational primitives that are supplied by the study of geometric algorithms.
Database indices rely on balance search tree data structures, as covered in this course.
and computational biology uses dynamic programming algorithms to measure similarity among genomes.
And the list goes on and on.
Obviously, I could give any number of examples here.
Let me just state one super obvious one.
which is that search engines use a tapestry of algorithms to efficiently compute the relevance of various web pages.
The most famous search algorithm which you may have heard of is the page rank algorithm in use by Google.
Indeed, in a December 2010 report to the United States Whitehouse, the President's Counsel of Advisers on Science and Technology argued that in many areas, performance gains due to improvements in algorithms, have vastly exceeded even the dramatic performance gains due to increased processor speed, as you'd be familiar with in the form of Moore's Law.
Third, although this is getting significantly outside the scope of this course, algorithms are increasingly being used to provide a novel lens on processes outside of Computer Science and Technology.
For example, the set of quantum computation has provided a new and computational viewpoint on quantum mechanics, price fluctuations in economic markets can be fruitfully viewed as an algorithmic process, and even evolution can be usefully thought of as, as a surprisingly search algorithm.
The last two reasons I'm going to give you might sound a little flipping but, you know, I, I think there is more than a grain of truth to both of them.
Now, I don't know about you but back when I was a student my favorite classes were always challenging classes but after
I struggled through them, I somehow felt I had a few more IQ points than when I started.
So, I hope this course provides a similar experience for many of you that one the one hand it's a bit of a struggle.
You find the, the concepts challenging but perhaps you feel just a tinge smarter after we're done.
Finally, I hope that by the end of the course, a constant fraction of you will agree with me that designing and analyzing algorithms is simply fun.
It's an endeavor that requires a rare blend of creativity and precision and it can cer tainly be frustrating at times, but even more than that, it is addictive.
So, let's now descend from these lofty generalities and get much more concrete.
And also, let's remember that we've all been learning and using algorithms since we were little kids.
So, once upon a time, in roughly third grade or so, you learned how to multiply two numbers.
Now, you probably weren't thinking in these terms at the time, but multiplying two numbers is certainly a well-defined computational problem and that procedure you learned back in third grade or so, is indeed an algorithm.
So, let's just make that a
little bit more precise.
In this computational problem, we're given as input, two numbers, let's say with n digits.
And to make things interesting, why don't you think about n as being really quite large, say in the thousands?
Maybe we're implementing an algorithm that's going to be used in a cryptography application where you need to keep track of really quite large numbers.
So, if we call the two input numbers x and y, the problem is simply to compute their product, xy.
times y.
So, a quick digression.
I'll certainly be the first to admit that my handwriting is not the greatest.
I got a C in penmanship back in elementary school, and I think the teacher was being a little generous but, you know, it's got an acquired taste, but trust me, you will get used to it.
Okay, back to integer multiplication.
Now, when we talk about procedures for multiplying two numbers, we're going to be interested in counting how many steps are required, in order to execute the multiplication.
So, how do we count a step?
We'll talk more about this more later, but for multiplying two numbers, let's just call a step, the addition or multiplication of two single digit numbers.
So, let's review the integer multiplication algorithm that we learned back in grade school, just by working through a concrete example.
Specifically, let's think of n equals four.
So, let's look at two four-digit numbers
let's say, five, six, seven, eight, and one, two, three, four .
Now, as you'll recall, the procedure we learned way back when was just to take each digit of the bottom number and multiply it by each of the top numbers.
And then to take each of those n partial products, and add them up.
So, for example, you start with the four.
You multiply it by eight, so you get 32.
Carry the three.
four times seven is 28, add the three, you get one, carry the three, and so on.
So, that gives you this first partial product.
22, seven, twelve.
Then, you do a shift, so you effectively put a zero in this final digit, and you repeat that procedure using the next digit, the three.
So again, three times eight is four, carry the two, and so on.
And you compute the final two partial products using the two and the one.
And having computed all of the partial products, you just add them up to get the final product.
Now, the question I'm interested in is, how much work, how many primitive operations did we do to multiply these two numbers.
And more generally, how many does it require to multiply two n digit numbers as a function of n.
Well, just to get sort of a ballpark view for what's going on, we started with two n digit numbers.
And at the end of the day, we basically filled out a grid of size roughly n by n, give or take a little bit.
So, just in ballpark terms, it seems that multiplying two n digit numbers required essentially a quadratic number of operations, a small number of operations to fill in each entry in this grid.
The grid is n by n roughly so that is roughly n squared operations.
In a little more detail, we could look at each of the partial products separately.
So, to compute, say, this first partial product, what do we do?
We take the four we multiplied it by each of the n digits on top.
We also did some carries, so that effects things a little bit.
But, in the end, we did somewhere between, say, n and the 2n, primitive operations to compute this first partial product.
And that's true, of course, for each of the n partial products.
So, that's roughly n operations for each of the n partial products .
So, that's roughly n squared operations.
It could be all of the partial products.