Fun Learning Algorithms Series - The Beauty of Algorithms

Fun Learning Algorithms Series - The Beauty of Algorithms

Disclaimer: This series is the learning and summary content of the book Fun Learning Algorithms . I recommend everyone to read this algorithm book as an introduction to algorithms.
Links to the original author's blog . There are no free electronic resources for this book. Please support the genuine version.

Book Introduction

The content of this book is divided into 7 chapters according to algorithm strategy.
- Chapter 1 introduces algorithm concepts, time complexity, space complexity concepts and calculation methods from the beauty of algorithms, simple problems and interesting stories, as well as the explosive incremental problem of algorithm design, so that readers can experience the mystery of algorithms.
- Chapters 2 to 7 introduce the design strategies, practical exercises, algorithm analysis, and optimization expansion of classic algorithms, including greedy algorithms, divide-and-conquer algorithms, dynamic programming, backtracking, branch-and-bound methods, linear programming, and network flows. Each algorithm has 4 to 10 examples, a total of 50 large-scale examples, including classic construction examples and practical application examples, according to problem analysis, algorithm design, perfect diagram, detailed pseudo-code explanation, actual combat drill, algorithm analysis and optimization expansion The process is clearly explained and easy to understand. The appendix introduces common data structures and related knowledge used for algorithm improvement, including sort function, priority queue, adjacency list, union search, quadrilateral inequality, permutation tree, Bellman's rule, augmenting path complexity calculation, maximum flow minimum cut theorems, etc.


Recommendation after reading

From a large number of interesting stories and images, the book vividly analyzes and describes the analysis process of algorithm problems to readers. A picture is worth a thousand words, and the effect of image combined memory is far superior to that of text explanation, and it is equipped with a special Q&A QQ Group communication, blog content record analysis, worth recommending.
The following content has been deleted or processed for self-understanding on the basis of the original work. For details, please refer to the original book.

Chapter 1 The Beauty of Algorithms

The famous Swiss scientist Professor N. Wirth once proposed: Data structure + algorithm = program.
The data structure is the skeleton of the program, and the algorithm is the soul of the program.
- What is an algorithm?
An algorithm is a set of mathematical models carefully designed to solve a specific problem and a series of operation steps on this mathematical model. These operation steps process and transform the input data described by the problem step by step, and finally get a definite result. . -From " The Fun of Algorithms " - Wang Xiaodong
The following contents are also summarized in this book, which are explained in advance due to the scattered space.
- The algorithm has the following properties.
- Finiteness: An algorithm is a finite sequence of several instructions, which always ends after executing several times, and it is impossible to stop forever.
- Deterministic: Each statement has a definite meaning without ambiguity.
- Feasibility: The algorithm can be implemented by a finite number of operations under the current environmental conditions.
- Inputs and outputs: There are zero or more inputs and one or more outputs.

  • Algorithms are good or bad
    • Correctness: Satisfies the requirements of the problem, operates normally, has no syntax errors, and
      passes software testing.
    • Readability: Concise and easy to understand, with appropriate and appropriate comments.
    • Robustness: The algorithm has a better response and processing of illegal data and operations.
    • Efficiency: The algorithm runs efficiently, that is, the algorithm takes a short time to run.
    • Low storage: Low storage refers to the low storage space required by the algorithm.
    • Six-word summary: high efficiency and low storage
  • The time complexity of the algorithm

    The asymptotic complexity of the algorithm is calculated separately for the best, worst and average cases, but when we examine an algorithm, we usually examine the worst case, not the best case, which has practical significance for measuring the quality of the algorithm.
    О(1)<О(logn)<О(n)<О(nlogn) <О(n)<О(n)<О(2) <О(n!)<О(n)


function growth curve
  • Quantitative metrics for code
    • Code Comment Rate Appropriate Comments Specification Comments
    • Average source code file length
    • Average function length Try not to exceed 50 lines per line
    • Average code dependencies Design pattern principles Decoupling and abstraction
    • Code nesting depth Avoid multiple loops and judgments
    • Test case coverage Handling of exceptions Handling of illegal operations
  • The space complexity of the algorithm,
  • The size of the space occupied by the algorithm. The auxiliary space of the algorithm is generally used as the standard to measure the space complexity. The original meaning of space complexity refers to how much storage space an algorithm takes up during its operation. The storage space occupied by the algorithm
    includes :

    • (1) Input/output data;
    • (2) The algorithm itself;
    • (3) Additional auxiliary space required.
  • Algorithm learning bottleneck

    Many people sigh: Why is the algorithm so difficult. Algorithms, as a discipline, have two almost parallel threads. One is data structures (data objects): numbers,
    matrices, sets, strings, arrays, graphs, expressions, distributions, etc. The other is algorithmic strategies: greedy, divide and
    conquer programming, linear programming, search, etc.
    Most of the traditional algorithm books focus on the inclusion of
    content , but ignore the display of the thinking process. Therefore, we have learned the classic algorithm, but we are puzzled
    by the process of algorithm design.

  • This chapter mainly explains the problem
    • (1) The number of program executions is used as a measure of time complexity.
    • (2) The time complexity is usually represented by the asymptotic upper bound symbol f(n).
    • (3) To measure the quality of the algorithm, the worst case of the algorithm is usually examined.
    • (4) The space complexity only calculates the auxiliary space.
    • (5) The space complexity of the recursive algorithm is to calculate the stack space used by the recursion.
    • (6) Try to avoid explosion-level incremental complexity when designing algorithms.
  • Do programmers have to know algorithms?
      The computer is actually a very stupid tool, so stupid that it has almost no IQ (at least for now), I temporarily understand it as programming for fools (this principle can better help you understand when you design algorithm ideas, exchange and transfer of variables, etc. Process).
      The computer will do it, but only if you tell it how to do it. An algorithm can be understood as a technique that will tell a computer what to do.
      The two most important points of a computer program are algorithms and data structures. People who say data structures and algorithms are useless are because they can't use them, they can't use them because they can't think of them, and they can't think of them because they can't. Just like elementary school students seldom understand advanced mathematics, when your level is below a certain level, you are in conflict with what you know. Not understanding does not mean disapproval. Existence is reasonable. The salary of algorithm engineer has been explained. question.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325446249&siteId=291194637