Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy committed Apr 5, 2015
1 parent 5a998f2 commit df01464
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ch02/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ T(n) = theta(n x lg(n) + n x lg(n / lg(n))), if k = lg(n)
```
* d. The desired value can be found by testing values from range [1, lg(n)].
##Problem 2-1 Bubble-Sort
##Problem 2-2 Bubble-Sort
* a. One more thing need to prove is that no item in A has been deleted nor item added into A'.In another word, A' must be a permutation of A.
* b. Loop invariant and its proof for lines 2-4
```cpp
Expand Down Expand Up @@ -309,3 +309,17 @@ I.M.T -> LI holds.
```
* d. time complexity = theta(n^2). Insertion-Sort is better. Because for average case and best case Insertion-Sort doesn't have to carry out theta(n) for its nested loop. whereas Bubble-Sort has to do so for any case.
##Problem 2-3 Horner’s rule
* Time complexity : theta(n)
* pseudocode
```python
Naive-Polynomial-Evaluation(arr_of_terms, x)
y = 0;
for term in arr_of_terms
X = 1
for i = 1 to term.k
X *= x
y += term.ak * X
```

0 comments on commit df01464

Please sign in to comment.