Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture materials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
generic software skills
lecture materials
Commits
3d7de23f
Commit
3d7de23f
authored
11 months ago
by
Tobias Koelling
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
3d6528d6
No related branches found
No related tags found
1 merge request
!24
complexity lecture
Pipeline
#66549
passed
11 months ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lectures/complexity/slides.qmd
+86
-45
86 additions, 45 deletions
lectures/complexity/slides.qmd
with
86 additions
and
45 deletions
lectures/complexity/slides.qmd
+
86
−
45
View file @
3d7de23f
...
...
@@ -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 task
s
#
Complexity Classe
s
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}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment