Skip to content
Snippets Groups Projects
Commit 3d7de23f authored by Tobias Koelling's avatar Tobias Koelling
Browse files

cleanup

parent 3d6528d6
No related branches found
No related tags found
1 merge request!24complexity lecture
Pipeline #66549 passed
......@@ -43,7 +43,7 @@ How many bytes are in a `double` temparature array<br/>of `3600` x `1800` x `100
:::
## Big-$\mathcal{O}$ Notation {auto-animate=true}
## Big-$\mathcal{O}$ Notation {auto-animate=true auto-animate-restart=true}
- growth in relation to input data size $n$
- big-$\mathcal{O}$ notation describes asymptotic behaviour
......@@ -75,38 +75,35 @@ None
:::{.smaller}
| Order | Notation |
| ------------ | ---------------------- |
| constant | $\mathcal{O}(1)$ |
| logarithmic | $\mathcal{O}(\log{n})$ |
| linear | $\mathcal{O}(n)$ |
| quadratic | $\mathcal{O}(n^2)$ |
| Order | Notation |
| ------------ | ------------------------ |
| constant | $\mathcal{O}(1)$ |
| logarithmic | $\mathcal{O}(\log{n})$ |
| linear | $\mathcal{O}(n)$ |
| quasilinear | $\mathcal{O}(n \log{n})$ |
| quadratic | $\mathcal{O}(n^2)$ |
:::
## Quiz {.special auto-animate=true auto-animate-restart=true}
## Selection of Time Complexities
How large is $\mathcal{O}(\log{n})$ on a computer?
:::{.smaller}
## Quiz {.special auto-animate=true}
Data structure Access Insert/Delete Search
--------------- ----------------------- ------------------------------------- -------------------------------------
Array $\mathcal{O}(1)$ $\mathcal{O}(n)$ $\mathcal{O}(n)$
Linked list $\mathcal{O}(n)$ $\mathcal{O}(1)$ $\mathcal{O}(n)$
Hash table --- $\mathcal{O}(1)$ -- $\mathcal{O}(n)$ $\mathcal{O}(1)$ -- $\mathcal{O}(n)$
Tree[^1] $\mathcal{O}(\log{n})$ $\mathcal{O}(\log{n})$ $\mathcal{O}(\log{n})$
How large is $\mathcal{O}(\log{n})$ on a computer?
[^1]: Some types of trees have $\mathcal{O}(\log{n})$ -- $\mathcal{O}(n)$ for insert/delete and search
`64`{data-id=64}
:::
## Quiz {.special auto-animate=true}
How large is $\mathcal{O}(\log{n})$ on a computer?
# specific algorithms
`64`{data-id=64} (at least on a 64 bit machine)
* sorting (e.g. bubble, quick, merge, bogo... [idea instructions](https://idea-instructions.com))
* nearest-neighbor (?)
* bisect (?) (ref to `git bisect`)
# Example
*sorting*
## Bubble Sort (1/2) {.leftalign}
......@@ -325,8 +322,9 @@ For an overview, [check Wikipedia](https://en.wikipedia.org/wiki/Sorting_algorit
:::
# an example
*(Fibonacci)*
# Example
*Fibonacci*
## Fibonacci series
......@@ -544,25 +542,9 @@ None
👉 Faster for **large** numbers
# Takeaway
## different algorithms for the same problem
Often there are different algorithms solving the same problem.
These can come with **very** different complexity ratings.
## scalar factors can matter
Big-$\mathcal{O}$ informs about large problems, especially for small problems, scalar factors may dominate.
## math can be better
*never use algorithms if math can do*
:::{.smaller .fragment}
... and prefer better algorithms if math can't do
:::
# Example
*hands-on*
## Hands-on example
......@@ -591,20 +573,79 @@ None
for which $f(x) > 0$. How many steps and checks are necessary to find $x$?
3. How many steps would be necessary if `x_values` contained 4100 values? And for 3900?
# Takeaway
## different algorithms for the same problem
Often there are different algorithms solving the same problem.
These can come with **very** different complexity ratings.
## Big-$\mathcal{O}$
Helps talking about complexity, informs about large problems.
## scalar factors can matter
For small problems, scalar factors may be more important than Big-$\mathcal{O}$.
:::{.smaller .fragment}
(but the problem is small anyways)
:::
## math can be better
*never use algorithms if math can do*
:::{.smaller .fragment}
... and prefer better algorithms if math can't do
:::
# Takeaway
## human time matters
## typical tasks
# Complexity Classes
For certain tasks (e.g. sorting, neighbors, averaging, or really anything...), think about what complexity class is expected.
If your program behaves differently, **change it** or **seek advice** from colleagues.
## $\mathcal{O}(1)$
*very nice*
* basic arithmetic
* array element access
* linked list insertion or removal
## $\mathcal{O}(\log{n})$
*ok for single element operations*
* tree / dict access, insertion or deletion
* nearest neighbor search
* bisect
## $\mathcal{O}(n)$
*nice if you have to touch many things*
* maps, reductions etc... (e.g. sum of an array)
* linked list element access
* array search
## $\mathcal{O}(n \log{n})$
*ok if you have to touch many things*
* sorting
* k-d tree construction
## $\mathcal{O}(n^2)$
*not so nice*
* matrix multiplication
* many algorithms by accident
## what would you expect?
Think about what complexity class is expected.<br/>
If your program behaves differently, **change it** or **seek advice** from colleagues.
# Complexity in Software Design
::::::::{.columns}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment