You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
y = sum(k = 0, k = n - (-1 + 1)) (a(k - 1 + 1) * x ^ k)
359
+
= sum(k = 0, k = n) (a(k) * x ^ k)
360
+
Hence, T holds.
361
+
362
+
L.I. holds.
363
+
```
364
+
365
+
* As shown above, this code fragment correctly evaluates a polynomial.
366
+
367
+
##Problem 2-4 Inversions
368
+
* Five inversions:
369
+
```cpp
370
+
{2,1}, {3,1}, {8,1}, {6,1}, {8,6}
371
+
```
372
+
* set {n, n-1, n-2, ...,2, 1}, i.e. numbers in descending order has most inversions.
373
+
```
374
+
number of inversions = n(n - 1)/2
375
+
```
376
+
* 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:
0 commit comments