Skip to content

Commit 538b05b

Browse files
committed
Fix tiny text tweaks
1 parent f31f769 commit 538b05b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Combinatorics/README.markdown

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ binomialCoefficient(30, 15) // prints 155117520
358358
binomialCoefficient(66, 33) // prints a very large number
359359
```
360360

361-
There's a faster approach to calculate `C(n, k)` in 'O(k)' time and 'O(1)' extra space.
361+
There's a faster approach to calculate `C(n, k)` in `O(k) time and `O(1)` extra space.
362362

363363
The idea behind it is that the formula for `C(n, k)` is:
364364

365365
n! n * (n - 1) * ... * 1
366366
C(n, k) = ------------- = ------------------------------------------
367367
(n - k)! * k! (n - k) * (n - k - 1) * ... * 1 * k!
368368

369-
After reduction of fractions, we get the following formula:
369+
After the reduction of fractions, we get the following formula:
370370

371-
n * (n - 1) * ... * (n - k + 1) (n - 0) * (n - 1) * ... * (n - k + 1)
371+
n * (n - 1) * ... * (n - k + 1) (n - 0) * (n - 1) * ... * (n - k + 1)
372372
C(n, k) = --------------------------------------- = -----------------------------------------
373373
k! (k - 0) * (k - 1) * ... * 1
374374

@@ -377,7 +377,7 @@ So the following code calculates the `C(n, k)` you're looking for:
377377
```swift
378378
func quickBinomialCoefficient(n: Int, _ k: Int) -> Int {
379379
var result = 1
380-
380+
381381
for i in 0..<k {
382382
result *= (n - i)
383383
result /= (i + 1)
@@ -388,7 +388,7 @@ func quickBinomialCoefficient(n: Int, _ k: Int) -> Int {
388388

389389
As there're the divisors for numbers from '1...k' among 'k' consecutive numbers, what is exactly we've got in the numerator of our fast formula every time we devide 'result' by '(i + 1)' we won't have a real number.
390390

391-
Now you can calculate `C(30, 15)` without any problems:
391+
Here's how you can use it:
392392

393393
```swift
394394
quickbinomialCoefficient(30, 15) // prints 155117520

0 commit comments

Comments
 (0)