Algorithmic Complexity
Algorithmic Complexity Amir Kirsh & Adam Segoli Schubert © All rights reserved image source: https://www.ac.tuwien.ac.at/people/szeider/cartoon Algorithmic Complexity @ CppCon 2021 Why this talk? 2Algorithmic Complexity @ CppCon 2021 Why this talk? Performance is the name of the game 3 Algorithmic Complexity @ CppCon 2021 Why this talk? Performance is the name of the game You all (hopefully) (hopefully) know that O(n) is better than O(n2) 4Algorithmic Complexity @ CppCon 2021 Performance is the name of the game You all (hopefully) know that O(n) is better than O(n2) But there is still important0 码力 | 52 页 | 1.01 MB | 5 月前3C++ Con 2024: Amortized Complexity
Amortized O(1) Complexity Andreas Weis CppCon 20242/32 Runtime Complexity f ∈ O(g) ⇐⇒ ∃ C > 0. ∃ x0 > 0. ∀ x > x0 : |f (x)| ≤ C · |g(x)|3/32 Child’s play!4/32 What is amortized complexity?4/32 What amortized complexity?4/32 What is amortized complexity?4/32 What is amortized complexity?4/32 What is amortized complexity?4/32 What is amortized complexity?4/32 What is amortized complexity?5/32 Amortized push_back (3);10/32 Cost of vector::push back v.push_back (3);11/32 Worst case complexity?11/32 Worst case complexity? O(n) n: Number of elements in the vector12/32 push back with an O(n) budget0 码力 | 60 页 | 2.56 MB | 5 月前3Quantifying Accidental Complexity: An empirical look at teaching and using C++
Quantifying Accidental Complexity: An empirical look at teaching and using C++ Herb Sutter 9/21/2020 1 Herb Sutter 4 We’re “paying taxes” all the time Productivity Correctness and quality Tooling Tooling Teaching, learning, hiring, training 2 4Quantifying Accidental Complexity: An empirical look at teaching and using C++ Herb Sutter 9/21/2020 2 5 Common claim: “C++ is too complex” This talk's count 6 Essential complexity Inherent in the problem, present in any solution Accidental complexity Artifact of a specific solution design 5 6Quantifying Accidental Complexity: An empirical look0 码力 | 36 页 | 2.68 MB | 5 月前3Rust算法教程 The Algos (algorithms)
sort algorithm. /// /// Time complexity is `O(n + k)` on average, where `n` is the number of elements, /// `k` is the number of buckets used in process. /// /// Space complexity is `O(n + k)`, as it sorts rs/print.html 36/270 基数排序 /// Sorts the elements of `arr` in-place using radix sort. /// /// Time complexity is `O((n + b) * logb(k))`, where `n` is the number of elements, /// `b` is the base (the radix) `n` and `b` are roughly the same maginitude, this algorithm runs in linear time. /// /// Space complexity is `O(n + b)`. pub fn radix_sort(arr: &mut [u64]) { let max: usize = match arr.iter().max()0 码力 | 270 页 | 8.46 MB | 1 年前3Back to Basics: Classic 9STL
• Semantically based interoperability guarantees • Efficient • No penalty for generality • Complexity guarantees at the interface level • Natural • C/C++ machine model and programming paradigm • • Semantically based interoperability guarantees • Efficient • No penalty for generality • Complexity guarantees at the interface level • Natural • C/C++ machine model and programming paradigm • Copyright © 2021 Bob Steagall Complexity and the Big-O Notation • Complexity refers to the runtime cost of an algorithm • Big-O notation expresses the relative complexity of an algorithm 16 Type Notation0 码力 | 75 页 | 603.36 KB | 5 月前3The Roles of Symmetry And Orthogonality In Design
predictability and consistent behavior (once pattern is recognized) Enables system scaling (in size and complexity)Charley Bay - charleyb123 at gmail dot com The Roles of Symmetry And Orthogonality In Design cppcon obvious for where a desired action should be placed • Are the steps guaranteed to occur? • If yes, complexity is reduced (edge cases are removed) • Can a step be “empty” (e.g., “do nothing” or “default” behavior cases and complexity: • Can a step be conditionally skipped? • Can the steps be reordered? • Can new (user-custom) steps be inserted? ctor() dtor() … Increasing Complexity Decreasing Complexity Domain-specific0 码力 | 151 页 | 3.20 MB | 5 月前3Hello 算法 1.0.0b1 Java版
理论估算 既然实际测试具有很大的局限性,那么我们是否可以仅通过一些计算,就获知算法的效率水平呢?答案 是肯定的,我们将此估算方法称为「复杂度分析 Complexity Analysis」或「渐近复杂度分析 Asymptotic Complexity Analysis」。 复杂度分析评估的是算法运行效率随着输入数据量增多时的增长趋势。这句话有些拗口,我们可以将其分为三 个重点来理解: 2. 复杂度分析 hello‑algo.com 13 ‧“算法运行效率”可分为“运行时间”和“占用空间”,进而可将复杂度分为「时间复杂度 Time Complexity」 和「空间复杂度 Space Complexity」。 ‧“随着输入数据量增多时”代表复杂度与输入数据量有关,反映算法运行效率与输入数据量之间的关系; ‧“增长趋势”表示复杂度分析不关心算法具体使用了多少时间或占用了多少空间,而是给出一种“趋势性 常数阶的操作数量与输入数据大小 ? 无关,即不随着 ? 的变化而变化。 对于以下算法,无论操作数量 size 有多大,只要与数据大小 ? 无关,时间复杂度就仍为 ?(1) 。 // === File: time_complexity.java === /* 常数阶 */ int constant(int n) { int count = 0; int size = 100000; for (int i = 0;0 码力 | 186 页 | 14.71 MB | 1 年前3Hello 算法 1.0.0b1 Swift版
理论估算 既然实际测试具有很大的局限性,那么我们是否可以仅通过一些计算,就获知算法的效率水平呢?答案 是肯定的,我们将此估算方法称为「复杂度分析 Complexity Analysis」或「渐近复杂度分析 Asymptotic Complexity Analysis」。 复杂度分析评估的是算法运行效率随着输入数据量增多时的增长趋势。这句话有些拗口,我们可以将其分为三 个重点来理解: 2. 复杂度分析 hello‑algo.com 13 ‧“算法运行效率”可分为“运行时间”和“占用空间”,进而可将复杂度分为「时间复杂度 Time Complexity」 和「空间复杂度 Space Complexity」。 ‧“随着输入数据量增多时”代表复杂度与输入数据量有关,反映算法运行效率与输入数据量之间的关系; ‧“增长趋势”表示复杂度分析不关心算法具体使用了多少时间或占用了多少空间,而是给出一种“趋势性 常数阶的操作数量与输入数据大小 ? 无关,即不随着 ? 的变化而变化。 对于以下算法,无论操作数量 size 有多大,只要与数据大小 ? 无关,时间复杂度就仍为 ?(1) 。 // === File: time_complexity.swift === /* 常数阶 */ func constant(n: Int) -> Int { var count = 0 let size = 100_000 for _0 码力 | 190 页 | 14.71 MB | 1 年前3Hello 算法 1.0.0b1 Python版
理论估算 既然实际测试具有很大的局限性,那么我们是否可以仅通过一些计算,就获知算法的效率水平呢?答案 是肯定的,我们将此估算方法称为「复杂度分析 Complexity Analysis」或「渐近复杂度分析 Asymptotic Complexity Analysis」。 复杂度分析评估的是算法运行效率随着输入数据量增多时的增长趋势。这句话有些拗口,我们可以将其分为三 个重点来理解: 2. 复杂度分析 hello‑algo.com 13 ‧“算法运行效率”可分为“运行时间”和“占用空间”,进而可将复杂度分为「时间复杂度 Time Complexity」 和「空间复杂度 Space Complexity」。 ‧“随着输入数据量增多时”代表复杂度与输入数据量有关,反映算法运行效率与输入数据量之间的关系; ‧“增长趋势”表示复杂度分析不关心算法具体使用了多少时间或占用了多少空间,而是给出一种“趋势性 复杂度分析 hello‑algo.com 19 对于以下算法,无论操作数量 size 有多大,只要与数据大小 ? 无关,时间复杂度就仍为 ?(1) 。 # === File: time_complexity.py === def constant(n): """ 常数阶 """ count = 0 size = 100000 for _ in range(size): count +=0 码力 | 178 页 | 14.67 MB | 1 年前3Hello 算法 1.0.0b1 C++版
理论估算 既然实际测试具有很大的局限性,那么我们是否可以仅通过一些计算,就获知算法的效率水平呢?答案 是肯定的,我们将此估算方法称为「复杂度分析 Complexity Analysis」或「渐近复杂度分析 Asymptotic Complexity Analysis」。 复杂度分析评估的是算法运行效率随着输入数据量增多时的增长趋势。这句话有些拗口,我们可以将其分为三 个重点来理解: 2. 复杂度分析 hello‑algo.com 13 ‧“算法运行效率”可分为“运行时间”和“占用空间”,进而可将复杂度分为「时间复杂度 Time Complexity」 和「空间复杂度 Space Complexity」。 ‧“随着输入数据量增多时”代表复杂度与输入数据量有关,反映算法运行效率与输入数据量之间的关系; ‧“增长趋势”表示复杂度分析不关心算法具体使用了多少时间或占用了多少空间,而是给出一种“趋势性 常数阶的操作数量与输入数据大小 ? 无关,即不随着 ? 的变化而变化。 对于以下算法,无论操作数量 size 有多大,只要与数据大小 ? 无关,时间复杂度就仍为 ?(1) 。 // === File: time_complexity.cpp === /* 常数阶 */ int constant(int n) { int count = 0; int size = 100000; for (int i = 0;0 码力 | 187 页 | 14.71 MB | 1 年前3
共 788 条
- 1
- 2
- 3
- 4
- 5
- 6
- 79