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 6, 2015
1 parent 0731bac commit f3fc2c2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ch02/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,16 @@ L.I. holds.
* As shown above, this code fragment correctly evaluates a polynomial.
##Problem 2-3 Inversions
##Problem 2-4 Inversions
* Five inversions:
```cpp
{2,1}, {3,1}, {8,1}, {6,1}, {8,6}
```
* set {n, n-1, n-2, ...,2, 1}, i.e. numbers in descending order has most inversions.
```
number of inversions = n(n - 1)/2
```
* As shown below, the expression `A[i] > key` in line 5 Insertion-Sort is in essence checking for an inversion. So a function can be made to describe the relationship between the running time and number of inversions:
```cpp
T(n) = theta(n * number_of_inversions + n)
T(n) = theta(number_of_inversions + n)
```

0 comments on commit f3fc2c2

Please sign in to comment.