Understanding software development in advance (14): Algorithms in the program

Source: Internet
Author: User
Tags execution thread

Algorithm (algorithm), is the soul of the program. Wurth, a famous computer scientist and Turing Prize winner, has proposed a formula: Data structure + algorithm = program. Obviously, the algorithm occupies a very important position in the program.

In actual software development projects, whether intentionally designed or unintentionally, we are almost always dealing with algorithms. Small to define a variable, large to write a function, these are the algorithm implementation process.

Based on the author's actual project work, this paper introduces the application of the algorithm in C program.

1. Algorithm overview

What is an algorithm? Let's take a look at some of the definitions in computer books.

Classic book " Introduction to Algorithms " (cormen, machinery Industry Press), the authors believe that the algorithm is a series of computational steps used to convert input data to output results.

In Tan Haoqiang's "C programming " book, the algorithm is defined as the method and step to solve a problem.

" algorithm design and Analysis-c++ language description " (Chen Huinan, Electronic Industry publishing house) in the book, the author thinks that the algorithm is to solve a class of problems of any special method, an algorithm is a specific problem to solve the process of a description.

The above definition of the algorithm is biased to the theory, in the actual software development project, the algorithm is to use program code to achieve software requirements, is the software Development engineer logical thinking embodiment.

2. Graphical representation of the algorithm

In order to visualize the algorithm, different scholars have designed different methods, including: natural language, flow chart, n-S flowchart, pseudo code and so on. In the actual programming work, most of the flow chart is used to express the algorithm visually. The flowchart logic is clear and is well suited for developers to use.

Some commonly used flowchart symbols in software development projects are shown in Figure 1.

Figure 1 Some commonly used flowchart symbols

The benefits of using flowcharts include: First, it is helpful for developers to check the correctness and completeness of the algorithm, second, to facilitate peer review of the Program (Code review) and third, to facilitate the long-term maintenance of the program.

3. The application of the algorithm in the Real Software development project

For the company based on the algorithm, such as Google, Baidu, and so on, the algorithm is very important, they have a dedicated algorithm engineer posts; for the company that makes the product, comparatively, make the product to be the main, they pay attention to is the algorithm in the product application.

But whether it is a special algorithm engineer, or a general software development engineer, we will often deal with the algorithm. The following describes the author himself in the project work encountered some algorithmic problems.

3.1 Multiple threads to achieve the independence of the program function

In the book of computer operating systems, there are many introductions to threads, one of the benefits of which is that computers can do many things in parallel. In the actual software development project, the thread is actually realizes a function function, may realize the program different function independence.

In a project, the previous developer created a thread to implement three separate functions: scanning data from the database to generate local files (function a), deleting expired records in the database (function B), and deleting local expired files. Since these three features are not related to one another, but in the same function, it needs to be performed in the order of function A, function B, function C, which not only seriously affects the execution efficiency of the program (if function A is very long, then function B and function C will take a long time to execute). Moreover, the number of lines of code for this function appears to be very numerous and does not conform to the programming specification. At this point, the flow of the function is shown in Figure 2.

Figure 2 Single-threaded function execution process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.