mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 05:26:42 +08:00
deploy
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
|
||||
<title>2.1 Algorithm efficiency assessment - Hello Algo</title>
|
||||
<title>2.1 Algorithm Efficiency Evaluation - Hello Algo</title>
|
||||
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
|
||||
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
|
||||
<style>:root{--md-text-font:"Lato";--md-code-font:"JetBrains Mono"}</style>
|
||||
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
<div data-md-component="skip">
|
||||
|
||||
|
||||
<a href="#21-algorithm-efficiency-assessment" class="md-skip">
|
||||
<a href="#21-algorithm-efficiency-evaluation" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
<div class="md-header__topic" data-md-component="header-topic">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
2.1 Algorithm efficiency assessment
|
||||
2.1 Algorithm Efficiency Evaluation
|
||||
|
||||
</span>
|
||||
</div>
|
||||
@@ -371,7 +371,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Before starting
|
||||
Before Starting
|
||||
|
||||
|
||||
|
||||
@@ -388,7 +388,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Before starting
|
||||
Before Starting
|
||||
|
||||
|
||||
</label>
|
||||
@@ -487,7 +487,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
0.1 About this book
|
||||
0.1 About This Book
|
||||
|
||||
|
||||
|
||||
@@ -515,7 +515,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
0.2 How to read
|
||||
0.2 How to Use This Book
|
||||
|
||||
|
||||
|
||||
@@ -604,7 +604,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 1. Encounter with algorithms
|
||||
Chapter 1. Encounter With Algorithms
|
||||
|
||||
|
||||
|
||||
@@ -626,7 +626,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 1. Encounter with algorithms
|
||||
Chapter 1. Encounter With Algorithms
|
||||
|
||||
|
||||
</label>
|
||||
@@ -648,7 +648,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
1.1 Algorithms are everywhere
|
||||
1.1 Algorithms Are Everywhere
|
||||
|
||||
|
||||
|
||||
@@ -676,7 +676,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
1.2 What is an algorithm
|
||||
1.2 What Is an Algorithm
|
||||
|
||||
|
||||
|
||||
@@ -771,7 +771,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 2. Complexity analysis
|
||||
Chapter 2. Complexity Analysis
|
||||
|
||||
|
||||
|
||||
@@ -793,7 +793,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 2. Complexity analysis
|
||||
Chapter 2. Complexity Analysis
|
||||
|
||||
|
||||
</label>
|
||||
@@ -824,7 +824,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
2.1 Algorithm efficiency assessment
|
||||
2.1 Algorithm Efficiency Evaluation
|
||||
|
||||
|
||||
|
||||
@@ -842,7 +842,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
2.1 Algorithm efficiency assessment
|
||||
2.1 Algorithm Efficiency Evaluation
|
||||
|
||||
|
||||
|
||||
@@ -871,7 +871,7 @@
|
||||
<a href="#211-actual-testing" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
2.1.1 Actual testing
|
||||
2.1.1 Actual Testing
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -882,7 +882,7 @@
|
||||
<a href="#212-theoretical-estimation" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
2.1.2 Theoretical estimation
|
||||
2.1.2 Theoretical Estimation
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -912,7 +912,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
2.2 Iteration and recursion
|
||||
2.2 Iteration and Recursion
|
||||
|
||||
|
||||
|
||||
@@ -940,7 +940,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
2.3 Time complexity
|
||||
2.3 Time Complexity
|
||||
|
||||
|
||||
|
||||
@@ -968,7 +968,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
2.4 Space complexity
|
||||
2.4 Space Complexity
|
||||
|
||||
|
||||
|
||||
@@ -1061,7 +1061,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 3. Data structures
|
||||
Chapter 3. Data Structures
|
||||
|
||||
|
||||
|
||||
@@ -1083,7 +1083,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 3. Data structures
|
||||
Chapter 3. Data Structures
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1105,7 +1105,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
3.1 Classification of data structures
|
||||
3.1 Classification of Data Structures
|
||||
|
||||
|
||||
|
||||
@@ -1133,7 +1133,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
3.2 Basic data types
|
||||
3.2 Basic Data Types
|
||||
|
||||
|
||||
|
||||
@@ -1161,7 +1161,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
3.3 Number encoding *
|
||||
3.3 Number Encoding *
|
||||
|
||||
|
||||
|
||||
@@ -1189,7 +1189,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
3.4 Character encoding *
|
||||
3.4 Character Encoding *
|
||||
|
||||
|
||||
|
||||
@@ -1282,7 +1282,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 4. Array and linked list
|
||||
Chapter 4. Array and Linked List
|
||||
|
||||
|
||||
|
||||
@@ -1304,7 +1304,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 4. Array and linked list
|
||||
Chapter 4. Array and Linked List
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1354,7 +1354,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
4.2 Linked list
|
||||
4.2 Linked List
|
||||
|
||||
|
||||
|
||||
@@ -1410,7 +1410,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
4.4 Memory and cache *
|
||||
4.4 Memory and Cache *
|
||||
|
||||
|
||||
|
||||
@@ -1501,7 +1501,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
|
||||
@@ -1523,7 +1523,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 5. Stack and queue
|
||||
Chapter 5. Stack and Queue
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1601,7 +1601,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
5.3 Double-ended queue
|
||||
5.3 Double-Ended Queue
|
||||
|
||||
|
||||
|
||||
@@ -1692,7 +1692,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
|
||||
@@ -1714,7 +1714,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 6. Hash table
|
||||
Chapter 6. Hashing
|
||||
|
||||
|
||||
</label>
|
||||
@@ -1736,7 +1736,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.1 Hash table
|
||||
6.1 Hash Table
|
||||
|
||||
|
||||
|
||||
@@ -1764,7 +1764,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.2 Hash collision
|
||||
6.2 Hash Collision
|
||||
|
||||
|
||||
|
||||
@@ -1792,7 +1792,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
6.3 Hash algorithm
|
||||
6.3 Hash Algorithm
|
||||
|
||||
|
||||
|
||||
@@ -1931,7 +1931,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.1 Binary tree
|
||||
7.1 Binary Tree
|
||||
|
||||
|
||||
|
||||
@@ -1959,7 +1959,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.2 Binary tree traversal
|
||||
7.2 Binary Tree Traversal
|
||||
|
||||
|
||||
|
||||
@@ -1987,7 +1987,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.3 Array Representation of tree
|
||||
7.3 Array Representation of Tree
|
||||
|
||||
|
||||
|
||||
@@ -2015,7 +2015,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.4 Binary Search tree
|
||||
7.4 Binary Search Tree
|
||||
|
||||
|
||||
|
||||
@@ -2043,7 +2043,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
7.5 AVL tree *
|
||||
7.5 AVL Tree *
|
||||
|
||||
|
||||
|
||||
@@ -2206,7 +2206,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
8.2 Building a heap
|
||||
8.2 Building a Heap
|
||||
|
||||
|
||||
|
||||
@@ -2234,7 +2234,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
8.3 Top-k problem
|
||||
8.3 Top-K Problem
|
||||
|
||||
|
||||
|
||||
@@ -2397,7 +2397,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
9.2 Basic graph operations
|
||||
9.2 Basic Operations on Graphs
|
||||
|
||||
|
||||
|
||||
@@ -2425,7 +2425,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
9.3 Graph traversal
|
||||
9.3 Graph Traversal
|
||||
|
||||
|
||||
|
||||
@@ -2564,7 +2564,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
10.1 Binary search
|
||||
10.1 Binary Search
|
||||
|
||||
|
||||
|
||||
@@ -2592,7 +2592,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
10.2 Binary search insertion
|
||||
10.2 Binary Search Insertion
|
||||
|
||||
|
||||
|
||||
@@ -2620,7 +2620,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
10.3 Binary search boundaries
|
||||
10.3 Binary Search Edge Cases
|
||||
|
||||
|
||||
|
||||
@@ -2648,7 +2648,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
10.4 Hashing optimization strategies
|
||||
10.4 Hash Optimization Strategy
|
||||
|
||||
|
||||
|
||||
@@ -2676,7 +2676,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
10.5 Search algorithms revisited
|
||||
10.5 Search Algorithms Revisited
|
||||
|
||||
|
||||
|
||||
@@ -2825,7 +2825,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.1 Sorting algorithms
|
||||
11.1 Sorting Algorithms
|
||||
|
||||
|
||||
|
||||
@@ -2853,7 +2853,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.2 Selection sort
|
||||
11.2 Selection Sort
|
||||
|
||||
|
||||
|
||||
@@ -2881,7 +2881,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.3 Bubble sort
|
||||
11.3 Bubble Sort
|
||||
|
||||
|
||||
|
||||
@@ -2909,7 +2909,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.4 Insertion sort
|
||||
11.4 Insertion Sort
|
||||
|
||||
|
||||
|
||||
@@ -2937,7 +2937,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.5 Quick sort
|
||||
11.5 Quick Sort
|
||||
|
||||
|
||||
|
||||
@@ -2965,7 +2965,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.6 Merge sort
|
||||
11.6 Merge Sort
|
||||
|
||||
|
||||
|
||||
@@ -2993,7 +2993,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.7 Heap sort
|
||||
11.7 Heap Sort
|
||||
|
||||
|
||||
|
||||
@@ -3021,7 +3021,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.8 Bucket sort
|
||||
11.8 Bucket Sort
|
||||
|
||||
|
||||
|
||||
@@ -3049,7 +3049,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.9 Counting sort
|
||||
11.9 Counting Sort
|
||||
|
||||
|
||||
|
||||
@@ -3077,7 +3077,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
11.10 Radix sort
|
||||
11.10 Radix Sort
|
||||
|
||||
|
||||
|
||||
@@ -3170,7 +3170,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 12. Divide and conquer
|
||||
Chapter 12. Divide and Conquer
|
||||
|
||||
|
||||
|
||||
@@ -3192,7 +3192,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 12. Divide and conquer
|
||||
Chapter 12. Divide and Conquer
|
||||
|
||||
|
||||
</label>
|
||||
@@ -3214,7 +3214,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
12.1 Divide and conquer algorithms
|
||||
12.1 Divide and Conquer Algorithms
|
||||
|
||||
|
||||
|
||||
@@ -3242,7 +3242,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
12.2 Divide and conquer search strategy
|
||||
12.2 Divide and Conquer Search Strategy
|
||||
|
||||
|
||||
|
||||
@@ -3270,7 +3270,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
12.3 Building binary tree problem
|
||||
12.3 Building a Binary Tree Problem
|
||||
|
||||
|
||||
|
||||
@@ -3298,7 +3298,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
12.4 Tower of Hanoi Problem
|
||||
12.4 Hanoi Tower Problem
|
||||
|
||||
|
||||
|
||||
@@ -3435,7 +3435,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
13.1 Backtracking algorithms
|
||||
13.1 Backtracking Algorithm
|
||||
|
||||
|
||||
|
||||
@@ -3463,7 +3463,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
13.2 Permutation problem
|
||||
13.2 Permutations Problem
|
||||
|
||||
|
||||
|
||||
@@ -3491,7 +3491,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
13.3 Subset sum problem
|
||||
13.3 Subset-Sum Problem
|
||||
|
||||
|
||||
|
||||
@@ -3519,7 +3519,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
13.4 n queens problem
|
||||
13.4 N-Queens Problem
|
||||
|
||||
|
||||
|
||||
@@ -3616,7 +3616,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
Chapter 14. Dynamic programming
|
||||
Chapter 14. Dynamic Programming
|
||||
|
||||
|
||||
|
||||
@@ -3638,7 +3638,7 @@
|
||||
<span class="md-nav__icon md-icon"></span>
|
||||
|
||||
|
||||
Chapter 14. Dynamic programming
|
||||
Chapter 14. Dynamic Programming
|
||||
|
||||
|
||||
</label>
|
||||
@@ -3660,7 +3660,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.1 Introduction to dynamic programming
|
||||
14.1 Introduction to Dynamic Programming
|
||||
|
||||
|
||||
|
||||
@@ -3688,7 +3688,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.2 Characteristics of DP problems
|
||||
14.2 Characteristics of Dynamic Programming Problems
|
||||
|
||||
|
||||
|
||||
@@ -3716,7 +3716,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.3 DP problem-solving approach¶
|
||||
14.3 Dynamic Programming Problem-Solving Approach
|
||||
|
||||
|
||||
|
||||
@@ -3744,7 +3744,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.4 0-1 Knapsack problem
|
||||
14.4 0-1 Knapsack Problem
|
||||
|
||||
|
||||
|
||||
@@ -3772,7 +3772,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.5 Unbounded knapsack problem
|
||||
14.5 Unbounded Knapsack Problem
|
||||
|
||||
|
||||
|
||||
@@ -3800,7 +3800,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
14.6 Edit distance problem
|
||||
14.6 Edit Distance Problem
|
||||
|
||||
|
||||
|
||||
@@ -3937,7 +3937,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
15.1 Greedy algorithms
|
||||
15.1 Greedy Algorithm
|
||||
|
||||
|
||||
|
||||
@@ -3965,7 +3965,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
15.2 Fractional knapsack problem
|
||||
15.2 Fractional Knapsack Problem
|
||||
|
||||
|
||||
|
||||
@@ -3993,7 +3993,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
15.3 Maximum capacity problem
|
||||
15.3 Maximum Capacity Problem
|
||||
|
||||
|
||||
|
||||
@@ -4021,7 +4021,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
15.4 Maximum product cutting problem
|
||||
15.4 Maximum Product Cutting Problem
|
||||
|
||||
|
||||
|
||||
@@ -4154,7 +4154,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
16.1 Installation
|
||||
16.1 Programming Environment Installation
|
||||
|
||||
|
||||
|
||||
@@ -4182,7 +4182,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
16.2 Contributing
|
||||
16.2 Contributing Together
|
||||
|
||||
|
||||
|
||||
@@ -4210,7 +4210,7 @@
|
||||
<span class="md-ellipsis">
|
||||
|
||||
|
||||
16.3 Terminology
|
||||
16.3 Terminology Table
|
||||
|
||||
|
||||
|
||||
@@ -4327,7 +4327,7 @@
|
||||
<a href="#211-actual-testing" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
2.1.1 Actual testing
|
||||
2.1.1 Actual Testing
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -4338,7 +4338,7 @@
|
||||
<a href="#212-theoretical-estimation" class="md-nav__link">
|
||||
<span class="md-ellipsis">
|
||||
|
||||
2.1.2 Theoretical estimation
|
||||
2.1.2 Theoretical Estimation
|
||||
|
||||
</span>
|
||||
</a>
|
||||
@@ -4382,44 +4382,44 @@
|
||||
|
||||
|
||||
<!-- Page content -->
|
||||
<h1 id="21-algorithm-efficiency-assessment">2.1 Algorithm efficiency assessment<a class="headerlink" href="#21-algorithm-efficiency-assessment" title="Permanent link">¶</a></h1>
|
||||
<p>In algorithm design, we pursue the following two objectives in sequence.</p>
|
||||
<h1 id="21-algorithm-efficiency-evaluation">2.1 Algorithm Efficiency Evaluation<a class="headerlink" href="#21-algorithm-efficiency-evaluation" title="Permanent link">¶</a></h1>
|
||||
<p>In algorithm design, we pursue the following two levels of objectives sequentially.</p>
|
||||
<ol>
|
||||
<li><strong>Finding a Solution to the Problem</strong>: The algorithm should reliably find the correct solution within the specified range of inputs.</li>
|
||||
<li><strong>Seeking the Optimal Solution</strong>: For the same problem, multiple solutions might exist, and we aim to find the most efficient algorithm possible.</li>
|
||||
<li><strong>Finding a solution to the problem</strong>: The algorithm must reliably obtain the correct solution within the specified input range.</li>
|
||||
<li><strong>Seeking the optimal solution</strong>: Multiple solutions may exist for the same problem, and we hope to find an algorithm that is as efficient as possible.</li>
|
||||
</ol>
|
||||
<p>In other words, under the premise of being able to solve the problem, algorithm efficiency has become the main criterion for evaluating an algorithm, which includes the following two dimensions.</p>
|
||||
<p>In other words, under the premise of being able to solve the problem, algorithm efficiency has become the primary evaluation criterion for measuring the quality of algorithms. It includes the following two dimensions.</p>
|
||||
<ul>
|
||||
<li><strong>Time efficiency</strong>: The speed at which an algorithm runs.</li>
|
||||
<li><strong>Space efficiency</strong>: The size of the memory space occupied by an algorithm.</li>
|
||||
<li><strong>Time efficiency</strong>: The length of time the algorithm runs.</li>
|
||||
<li><strong>Space efficiency</strong>: The size of memory space the algorithm occupies.</li>
|
||||
</ul>
|
||||
<p>In short, <strong>our goal is to design data structures and algorithms that are both fast and memory-efficient</strong>. Effectively assessing algorithm efficiency is crucial because only then can we compare various algorithms and guide the process of algorithm design and optimization.</p>
|
||||
<p>There are mainly two methods of efficiency assessment: actual testing and theoretical estimation.</p>
|
||||
<h2 id="211-actual-testing">2.1.1 Actual testing<a class="headerlink" href="#211-actual-testing" title="Permanent link">¶</a></h2>
|
||||
<p>Suppose we have algorithms <code>A</code> and <code>B</code>, both capable of solving the same problem, and we need to compare their efficiencies. The most direct method is to use a computer to run these two algorithms, monitor and record their runtime and memory usage. This assessment method reflects the actual situation, but it has significant limitations.</p>
|
||||
<p>On one hand, <strong>it's difficult to eliminate interference from the testing environment</strong>. Hardware configurations can affect algorithm performance. For example, an algorithm with a high degree of parallelism is better suited for running on multi-core CPUs, while an algorithm that involves intensive memory operations performs better with high-performance memory. The test results of an algorithm may vary across different machines. This means testing across multiple machines to calculate average efficiency becomes impractical.</p>
|
||||
<p>On the other hand, <strong>conducting a full test is very resource-intensive</strong>. Algorithm efficiency varies with input data size. For example, with smaller data volumes, algorithm <code>A</code> might run faster than <code>B</code>, but with larger data volumes, the test results may be the opposite. Therefore, to draw convincing conclusions, we need to test a wide range of input data sizes, which requires excessive computational resources.</p>
|
||||
<h2 id="212-theoretical-estimation">2.1.2 Theoretical estimation<a class="headerlink" href="#212-theoretical-estimation" title="Permanent link">¶</a></h2>
|
||||
<p>Due to the significant limitations of actual testing, we can consider evaluating algorithm efficiency solely through calculations. This estimation method is known as <u>asymptotic complexity analysis</u>, or simply <u>complexity analysis</u>.</p>
|
||||
<p>Complexity analysis reflects the relationship between the time and space resources required for algorithm execution and the size of the input data. <strong>It describes the trend of growth in the time and space required by the algorithm as the size of the input data increases</strong>. This definition might sound complex, but we can break it down into three key points to understand it better.</p>
|
||||
<p>In short, <strong>our goal is to design data structures and algorithms that are "both fast and memory-efficient"</strong>. Effectively evaluating algorithm efficiency is crucial, because only in this way can we compare various algorithms and guide the algorithm design and optimization process.</p>
|
||||
<p>Efficiency evaluation methods are mainly divided into two types: actual testing and theoretical estimation.</p>
|
||||
<h2 id="211-actual-testing">2.1.1 Actual Testing<a class="headerlink" href="#211-actual-testing" title="Permanent link">¶</a></h2>
|
||||
<p>Suppose we now have algorithm <code>A</code> and algorithm <code>B</code>, both of which can solve the same problem, and we need to compare the efficiency of these two algorithms. The most direct method is to find a computer, run these two algorithms, and monitor and record their running time and memory usage. This evaluation approach can reflect the real situation, but it also has considerable limitations.</p>
|
||||
<p>On one hand, <strong>it is difficult to eliminate interference factors from the testing environment</strong>. Hardware configuration affects the performance of algorithms. For example, if an algorithm has a high degree of parallelism, it is more suitable for running on multi-core CPUs; if an algorithm has intensive memory operations, it will perform better on high-performance memory. In other words, the test results of an algorithm on different machines may be inconsistent. This means we need to test on various machines and calculate average efficiency, which is impractical.</p>
|
||||
<p>On the other hand, <strong>conducting complete testing is very resource-intensive</strong>. As the input data volume changes, the algorithm will exhibit different efficiencies. For example, when the input data volume is small, the running time of algorithm <code>A</code> is shorter than algorithm <code>B</code>; but when the input data volume is large, the test results may be exactly the opposite. Therefore, to obtain convincing conclusions, we need to test input data of various scales, which requires a large amount of computational resources.</p>
|
||||
<h2 id="212-theoretical-estimation">2.1.2 Theoretical Estimation<a class="headerlink" href="#212-theoretical-estimation" title="Permanent link">¶</a></h2>
|
||||
<p>Since actual testing has considerable limitations, we can consider evaluating algorithm efficiency through calculations alone. This estimation method is called <u>asymptotic complexity analysis</u>, or <u>complexity analysis</u> for short.</p>
|
||||
<p>Complexity analysis can reflect the relationship between the time and space resources required for algorithm execution and the input data scale. <strong>It describes the growth trend of the time and space required for algorithm execution as the input data scale increases</strong>. This definition is somewhat convoluted, so we can break it down into three key points to understand.</p>
|
||||
<ul>
|
||||
<li>"Time and space resources" correspond to <u>time complexity</u> and <u>space complexity</u>, respectively.</li>
|
||||
<li>"As the size of input data increases" means that complexity reflects the relationship between algorithm efficiency and the volume of input data.</li>
|
||||
<li>"The trend of growth in time and space" indicates that complexity analysis focuses not on the specific values of runtime or space occupied, but on the "rate" at which time or space increases.</li>
|
||||
<li>"As the input data scale increases" means that complexity reflects the relationship between algorithm running efficiency and input data scale.</li>
|
||||
<li>"Growth trend of time and space" indicates that complexity analysis focuses not on the specific values of running time or occupied space, but on how "fast" time or space grows.</li>
|
||||
</ul>
|
||||
<p><strong>Complexity analysis overcomes the disadvantages of actual testing methods</strong>, reflected in the following aspects:</p>
|
||||
<p><strong>Complexity analysis overcomes the drawbacks of the actual testing method</strong>, reflected in the following aspects.</p>
|
||||
<ul>
|
||||
<li>It does not require actually running the code, making it more environmentally friendly and energy efficient.</li>
|
||||
<li>It is independent of the testing environment and applicable to all operating platforms.</li>
|
||||
<li>It can reflect algorithm efficiency under different data volumes, especially in the performance of algorithms with large data volumes.</li>
|
||||
<li>It does not need to actually run the code, making it more environmentally friendly and energy-efficient.</li>
|
||||
<li>It is independent of the testing environment, and the analysis results are applicable to all running platforms.</li>
|
||||
<li>It can reflect algorithm efficiency at different data volumes, especially algorithm performance at large data volumes.</li>
|
||||
</ul>
|
||||
<div class="admonition tip">
|
||||
<p class="admonition-title">Tip</p>
|
||||
<p>If you're still confused about the concept of complexity, don't worry. We will cover it in detail in subsequent chapters.</p>
|
||||
<p>If you are still confused about the concept of complexity, don't worry—we will introduce it in detail in subsequent chapters.</p>
|
||||
</div>
|
||||
<p>Complexity analysis provides us with a "ruler" to evaluate the efficiency of an algorithm, enabling us to measure the time and space resources required to execute it and compare the efficiency of different algorithms.</p>
|
||||
<p>Complexity is a mathematical concept that might be abstract and challenging for beginners. From this perspective, complexity analysis might not be the most suitable topic to introduce first. However, when discussing the characteristics of a particular data structure or algorithm, it's hard to avoid analyzing its speed and space usage.</p>
|
||||
<p>In summary, it is recommended to develop a basic understanding of complexity analysis before diving deep into data structures and algorithms, <strong>so that you can perform complexity analysis on simple algorithms</strong>.</p>
|
||||
<p>Complexity analysis provides us with a "ruler" for evaluating algorithm efficiency, allowing us to measure the time and space resources required to execute a certain algorithm and compare the efficiency between different algorithms.</p>
|
||||
<p>Complexity is a mathematical concept that may be relatively abstract for beginners, with a relatively high learning difficulty. From this perspective, complexity analysis may not be very suitable as the first content to be introduced. However, when we discuss the characteristics of a certain data structure or algorithm, it is difficult to avoid analyzing its running speed and space usage.</p>
|
||||
<p>In summary, it is recommended that before diving deep into data structures and algorithms, <strong>you first establish a preliminary understanding of complexity analysis so that you can complete complexity analysis of simple algorithms</strong>.</p>
|
||||
|
||||
<!-- Source file information -->
|
||||
|
||||
@@ -4442,7 +4442,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../"
|
||||
class="md-footer__link md-footer__link--prev"
|
||||
aria-label="Previous: Chapter 2. &nbsp; Complexity analysis"
|
||||
aria-label="Previous: Chapter 2. &nbsp; Complexity Analysis"
|
||||
rel="prev"
|
||||
>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -4454,7 +4454,7 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 2. Complexity analysis
|
||||
Chapter 2. Complexity Analysis
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
@@ -4466,7 +4466,7 @@ aria-label="Footer"
|
||||
<a
|
||||
href="../iteration_and_recursion/"
|
||||
class="md-footer__link md-footer__link--next"
|
||||
aria-label="Next: 2.2 Iteration and recursion"
|
||||
aria-label="Next: 2.2 Iteration and Recursion"
|
||||
rel="next"
|
||||
>
|
||||
<div class="md-footer__title">
|
||||
@@ -4474,7 +4474,7 @@ aria-label="Footer"
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
2.2 Iteration and recursion
|
||||
2.2 Iteration and Recursion
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
@@ -4567,7 +4567,7 @@ aria-label="Footer"
|
||||
<nav class="md-footer__inner md-grid" aria-label="Footer" >
|
||||
|
||||
|
||||
<a href="../" class="md-footer__link md-footer__link--prev" aria-label="Previous: Chapter 2. &nbsp; Complexity analysis">
|
||||
<a href="../" class="md-footer__link md-footer__link--prev" aria-label="Previous: Chapter 2. &nbsp; Complexity Analysis">
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
|
||||
@@ -4577,20 +4577,20 @@ aria-label="Footer"
|
||||
Previous
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
Chapter 2. Complexity analysis
|
||||
Chapter 2. Complexity Analysis
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
<a href="../iteration_and_recursion/" class="md-footer__link md-footer__link--next" aria-label="Next: 2.2 Iteration and recursion">
|
||||
<a href="../iteration_and_recursion/" class="md-footer__link md-footer__link--next" aria-label="Next: 2.2 Iteration and Recursion">
|
||||
<div class="md-footer__title">
|
||||
<span class="md-footer__direction">
|
||||
Next
|
||||
</span>
|
||||
<div class="md-ellipsis">
|
||||
2.2 Iteration and recursion
|
||||
2.2 Iteration and Recursion
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-footer__button md-icon">
|
||||
|
||||
Reference in New Issue
Block a user