Notes for Intorduction To Algorithms

In the first class, we talked about the Analysis of Algorithms. It is the theoritical study of computer-program performance and resouse useage.We study how to make things fast.There are still lots of things are far more important than algotithm.Why should we study performance? However, it's the bottom of the heap.Here are some reasons:
1.Performance measures the line between feasible and the infeasible.

2.Algorithms give you a language for talking about program behavior

I want greater  functionality, so people will program in Java, even it's slower than C. But it's worth it because it got all these object-oriented features and so forth exception mechanisims and so on. You can use performance to exchange other things, it' just like currency

3.it's tons of fun

 

Problem sorting No.1

we have a sequence a1,a2 up to an of numbers as input.And our output is a permutation of those numbers. A permutation is a rearrangement of the numbers.

such that a1 is less than or equal to a2. Such that they are monotonically uncreasing in size.Take a bunch of numbers, put them in order.

Insertion sort:

we use indentation as a means of showing the nesting of things, it's generally a bad idea, because if things go over one page to another, you cannot tell what level of nesting it is. Whereas, with explicit braces it's much easier to tell.

It takes an array A, we are looking at some element here j. And we pull a value out here that we call the key, then we find the right place and pull it in.

First of all, let's take a look at the issue of running time.

worst case analysis

Average case It's the time of every input times the probability that it will be that input. It's a way of taking a weighted average. stat distr

Best case cheat

Ingore the machine-dependent constants. Look at growth of running time.

Drop low-order terms. Ingore leading constants

arithmetic series 等差数列

 

Merge sort

 

红黑树

 

posted @ 2017-06-03 16:15  miao_a_miao  阅读(134)  评论(0)    收藏  举报