Skip to content

Commit

Permalink
upd time-complexities.md
Browse files Browse the repository at this point in the history
  • Loading branch information
halyph committed Oct 16, 2023
1 parent 130d615 commit 9e819b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 10 additions & 10 deletions docs/wiki/misc/time-complexities.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Examples Related to Time Complexities

### Ex 1: `O(n)` for loop
### Ex 1: **O(n)** for loop

```go
package main
Expand All @@ -24,7 +24,7 @@ func main() {
}
```

### Ex 2: `O(n^2)` Nested for loop
### Ex 2: **O(n^2^)** Nested for loop

```go
package main
Expand All @@ -48,7 +48,7 @@ func main() {
}
```

### Ex 3: `O(n^2)` Arithmetic series
### Ex 3: **O(n^2^)** Arithmetic series

The exact number of steps will go the same way as those of the arithmetic series. In this case, the time complexity will be: `O(n + (n−1) + (n−2) + ...) = O(n(n+1)/2) = O(n^2)`

Expand All @@ -74,7 +74,7 @@ func main() {
}
```

### Ex 4: `O(log(n))` Double the iteration variable
### Ex 4: **O(log(n))** Double the iteration variable

```go
package main
Expand All @@ -98,7 +98,7 @@ func main() {
}
```

### Ex 5: `O(log(n))` Half the iteration variable
### Ex 5: **O(log(n))** Half the iteration variable

```go
package main
Expand All @@ -122,7 +122,7 @@ func main() {
}
```

### Ex 6: `O(n ^ (3/2))` Square root iteration
### Ex 6: **O(n ^3/2^)** Square root iteration

In this example, we consider the size of the inner loop as the square root of `n`. The size of our program is `(n∗√n)`. Thus, its time complexity is `O(n ^ (3/2))`.

Expand Down Expand Up @@ -150,7 +150,7 @@ func main() {
}
```

### Ex 7: Nested loop in `O(n)`
### Ex 7: Nested loop in **O(n)**

```go
package main
Expand All @@ -175,7 +175,7 @@ func main() {

```

### Ex 8: `O(n^2)` Arithmetic progression
### Ex 8: **O(n^2^)** Arithmetic progression

```go
package main
Expand All @@ -199,7 +199,7 @@ func main() {
}
```

### Ex 9: `O(n^3)` Triple nested loop
### Ex 9: **O(n^3^)** Triple nested loop

```go
package main
Expand All @@ -225,7 +225,7 @@ func main() {
}
```

### Ex 10: Multiple loops in `O(n)`
### Ex 10: Multiple loops in **O(n)**

This is a tricky one. In this example, `j` is not initialized for every iteration. For `i=0`, the loop of `j` executes completely. But for the remaining values of `i`, the loop of `j` does not execute. Time complexity, in this case, is `O(n)`

Expand Down
9 changes: 8 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ markdown_extensions:
- smarty
- extra
- codehilite
- pymdownx.magiclink
- pymdownx.caret
- pymdownx.critic
- pymdownx.details
- pymdownx.keys
- pymdownx.magiclink
- pymdownx.mark
- pymdownx.superfences
- pymdownx.tilde
- pymdownx.highlight:
auto_title: true
linenums: true
- mdx_truly_sane_lists
- tables
- attr_list
Expand Down

0 comments on commit 9e819b3

Please sign in to comment.