Algorithmic ComplexityAlgorithmic 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 | 6 月前3
C++ Con 2024: Amortized ComplexityAmortized 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 | 6 月前3
Quantifying 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 | 6 月前3
Back 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 | 6 月前3
The Roles of Symmetry And Orthogonality In Designpredictability 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 | 6 月前3
Hello 算法 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
Hello 算法 1.0.0b2 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 码力 | 197 页 | 15.72 MB | 1 年前3
Constructing Generic AlgorithmsQUESTIONS 1. Am I using any standard algorithms? Which concept(s) do they require? also informs complexity guarantees, maybe different for different concepts 30 . 1ITERATOR CONCEPT QUESTIONS ITERATOR CONCEPT QUESTIONS 1. Am I using any standard algorithms? Which concept(s) do they require? also informs complexity guarantees, maybe different for different concepts 2. Do I look at an element after moving past QUESTIONS 1. Am I using any standard algorithms? Which concept(s) do they require? also informs complexity guarantees, maybe different for different concepts 2. Do I look at an element after moving past0 码力 | 145 页 | 8.44 MB | 6 月前3
Taming the C++ Filter Viewconstant complexity – begin() has constant complexity – end() has constant complexity • Guarantees for Views – Initialization has constant complexity – begin() has amortized constant complexity – end() end() has amortized constant complexity [range.range]: Given an expression t such that decltype((t)) is T&, T models concept std::range only if ... (3.2) — both ranges::begin(t) and ranges::end(t) are amortized constant complexity • begin() is thread safe (using mutable) – Performance issue: Makes begin() very expensive • No caching at all – Performance issue: Some use cases have quadratic complexity • Reverse0 码力 | 43 页 | 2.77 MB | 6 月前3
DEDUCING this PATTERNSexplosion of complexity with CRTP layeringSO WE HAVE IMPROVEMENTS more functionality for less code more comprehensive functions (compiler makes the overloads for us) no explosion of complexity with CRTP for less code more comprehensive functions (compiler makes the overloads for us) no explosion of complexity with CRTP layering These are all great, but fundamentally they aren't new. Let's look at some Implementation complexity Compile time? (if you would avoid completeness)ADT STYLE DISADVANTAGES Templates Implementation complexity Compile time? (if you would avoid completeness) Over-deduction complexity You0 码力 | 126 页 | 5.15 MB | 6 月前3
共 143 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15













