Introduction to chapt 1 in algorithm design and analysis basics

Source: Internet
Author: User
ArticleDirectory
    • 1.1 concepts of Algorithms
    • 1.2 algorithm solving steps
    • 1.3 Important Question Types
    • 1.4 Data Structure
1.1 Algorithm Concept

1. Calculate the maximum public approx.

Euclidean Algorithm:

 
Gcd (m, n) = gcd (n, m % N)

 

2. 2 ~ Sequence of continuous prime numbers of N-sieve (sieve)

Algorithm: each scan removes the candidate prime number from which it is determined to be a multiple of the prime number.

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  
2 3 5   7   9   11   13   15   17   19   21   23   25  
2 3   5   7       11   13       17   19       23   25  
2 3   5   7       11   13       17   19       23      

In order to eliminate the multiples of P, avoid multiple elimination of the same number. For example, if we delete the multiples of 2 and 3, we need to remove 6 from the table above.

We note that when the multiples of P are eliminated, the first number to be considered is pxp, because 2 P, P-1) P are all deleted before.

Obviously, pxp should be no greater than N, that is, P <=, as the condition for loop times to end

 
# Include <iostream>
 
# Include <cmath>
 
Using NamespaceSTD;
 
 
 
VoidPrime_sq (IntN)
 
{
 
IntArr [n-1];
 
For(IntI = 0; I <n-1; ++ I)
 
{
 
Arr [I] = I + 2;
 
}
IntJ = 0;
 
While(ARR [J] <= SQRT (n ))
 
{
 
For(IntI = arr [J] * arr [J]-2; I <n-1; ++ I)
 
{
 
If(ARR [I] % arr [J] = 0)
 
Arr [I] = 0;
 
}
 
While(ARR [++ J] = 0 );
 
}
 
 
 
For(IntI = 0; I <n-1; ++ I)
 
{
If(ARR [I]! = 0)
 
Cout <arr [I] <"";
 
}
 
}
 
 
 
IntMain ()
 
{
 
Prime_sq (25 );
 
 
 
System ("Pause");
 
Return0;
 
}
1.2 algorithm solving steps

1.2.1 understand the problem

Fully understand the problem.

Read the Problem description carefully. If you have any questions, ask the questions, handle some small examples manually, and consider special circumstances. If necessary, continue to raise questions.

 

There are several types of problems that frequently occur in computer applications. If they belong to one of them, you can use known algorithms to solve them, but you must understand their advantages and disadvantages. We often cannot find a fully available algorithm, so we have to design our own algorithm.

1.2.2 understand the performance of computing devices

Feng nuoman: Random Access Machine

Commands are run one by one, and each operation is performed one by one. The algorithm designed to run on this machine becomesSequential Algorithm.

The updated computer can execute multiple operations at the same time, that is, B parallel computing. The algorithm that can take advantage of this computing performance becomesParallel Algorithms

 

1.2.3 In Exact Solution And Approximate Solution Select

Why do we need an approximate solution?

    • Some problems cannot be solved accurately.
    • Because of the inherent complexity of some problems, it is too slow to use known accurate algorithms to solve them.
1.2.4 determine an appropriate data structure

Some algorithms do not require exquisite representation of input data, while some algorithms do need to be based on some well-designed data structures.

 

1.2.5 Algorithm Design Technology

Algorithm Design Technology (also known as "strategy" or "Example") is a general method used to solve problems in different computing fields.

    • They can provide guidance when designing algorithms for New Problems
    • Algorithm Design Technology can classify algorithms according to internal design concepts.
1.2.6 detailed algorithm expression method
    • Natural Language
    • PseudoCode
1.2.7 verify the correctness of the Algorithm

The general method of proof is to useMathematical induction,Because the iteration process of the algorithm originally provided a series of steps required for this proof.

The verification is incorrect. You only need to provide an input instance that cannot be correctly processed by an algorithm.

Approximation algorithms, we often try to prove that the error produced by this algorithm does not exceed our predefined range.

1.2.8 Analysis Algorithm
    • Efficiency

      • Time Efficiency
      • Space Efficiency
    • Simplicity
    • General
      • General issues solved by Algorithms
      • General Input accepted by the algorithm

1.2.9 AlgorithmProgramImplementation

 

1.3 Important Question Types
    • Sort
    • Search
    • String processing
    • Graph Problems
    • Combination Problem
    • Geometric Problem
    • Numerical Problem
1.3.1 sorting
    • Stability

      • If an input list contains two equal elements, their positions are I and j, I <J. In the sorted list, their positions are I ', and J ', if there is still ''<J', the sorting is stable.
    • Extra storage space
      • In addition to individual storage units, if no additional storage space is required, the sorting isLocal sorting(In-Place)
1.3.2 search)
    • Sequential search
    • Half-fold search-high efficiency but limited application
    • Express the original collection as another form-information storage for large databases

Balance between efficient search and delete/insert operations

1.3.3 string processing

Processing of non-numerical data: bit strings and Gene Sequences

String Matching

1.3.4 graph Problems

A graph is called an object of interest for both theoretical and practical reasons.

Graphs can be used to model a wide range of practical applications, including transportation, communication networks, project schedules, and various competitions.

A recently interesting application is to estimate the diameter of the Internet, that is, the maximum number of links that will pass through the shortest path between two webpages.

Basic Graph algorithms include:

    • Graph traversal algorithm (how to access all nodes in the network at a time ?)
    • Shortest Route Algorithm (which is the best route between two cities ?)
    • Topological sorting of Directed Graphs (are the prerequisites for a series of processes consistent or self-contradictory ?)

Some graph problems are very difficult to calculate:

Traveling Salesman Problem: Find the shortest path for access to N cities, and ensure that each city only accesses one

Color Filling: Color the vertex in the graph with the least variety of colors and ensure that the colors of the two adjacent vertices are different.

 

1.3.5 combination Problem

From a more abstract perspective, the traveling salesman problem and the graphic coloring problem are special cases of the combination problem.

There are some problems that require (explicit or implicit) a composite object, such as an arrangement, a combination, or a subset, these objects meet specific conditions and have the features we want (for example, maximizing value or minimizing costs)

From both theoretical and practical perspectives, the most difficult problem in the field of computing in the combiner room:

    • As the scale of the problem increases, the number of composite objects increases rapidly.
    • No known algorithm can precisely solve the vast majority of such problems within an acceptable period of time. Moreover, computer scientists suspect that such algorithms do not exist.

But some algorithms can be solved with efficient algorithms, thanks to luck and exceptions.

1.3.6 geometric issues

Applications of Geometric algorithms: computer graphics, robotics, and tomography

Here we only discuss two classic geometric issues:

    • Closest to the problem-N points on a given plane, calculate the two closest points
    • Convex Hull problem-find a Minimum Convex Polygon that can include all the points in a given set

 

1.3.7 numeric Problem

Problems in the study of such textbooks as numerical analysis: Solving Equations and equations, calculating definite points, and finding function values

Numerical analysis has lost its dominance in computer science and industry, but it is still very important to have the basic concept of numerical algorithms.

1.4 Data Structure 1.4.1 linear Data Structure
    • Array
    • Linked List
1.4.2 figure

1. Graph Representation

    • Adjacent matrix
    • Adjacent linked list

2. Weighted Graph

3. Path and ring

    • Simple path-all edges in the path are different from each other
    • Connectivity
    • Ring

4. Tree

A tree is a connectionless graph.

The forest is a graph without loops but not necessarily connected.

Important Properties of the tree:

    • The number of edges of a tree is always less than the number of its vertices. 1: | E |=| v |-1
    • Free tree-> rooted tree

Root tree: A simple path from vertex to vertex always exists between any two vertices of the tree.

Application of the tree: Describe the hierarchy (file directory, organization structure of the enterprise), Dictionary implementation, efficient storage of ultra-large data sets, and data encoding.

Status space tree-> tracing and branch boundaries

Concepts:

    • Ancestor
    • Parents
    • Children and Children
    • Brother
    • Leaf node
    • Subtree
    • Vertex depth: the length of a simple path from the root to the vertex
    • Tree Height: length of the longest simple path from the root node to the leaf node + 1

Ordered Tree: a tree with roots. All children of each vertex in the tree are ordered. For example, binary tree

Binary Search Tree:

For a binary tree with n vertices whose height is h, there is an inequality,

1.4.5 set and Dictionary (MAP)

Set operation:

    • Checks whether a given item is a member of a given set.
    • Returns the union of two sets.
    • Returns the intersection of two sets.

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.