Basic knowledge about algorithms and data structures

Source: Internet
Author: User

To work in a computer, data must first be processed and processed by a computer. In a simple classification, data is classified into numerical data and non-numerical data. Numerical data is mainly used in engineering and scientific computing; instead of numerical data, such as sound and images, are stored in the physical media in binary form in computers. Each binary bit is a bit, and the eight binary digits are a byte (bytes ).

To talk about the data structure, you must understand the data type (that is, a set of values and a group of operations defined on the set .); Data types include atomic data type and structural data type (Composite data type ). The so-called structure data type refers to the data type composed of the atomic data type or other structural data types. Data structure refers to the way computers store organizational data. Data structures are classified as follows: Linear Structures (queues, linked lists, stacks, and so on); Non-linear structures (trees and graphs ).

The algorithm design depends on the data structure, and the implementation of the algorithm depends on the data structure. Data operations are Operation algorithms defined on top of the data structure. Therefore, the design of algorithms is inseparable from the data structure. However, the design of algorithms also has its own skills and methods. Below are several common algorithm design strategies.

1. Greedy Algorithm

2. Divide and conquer Algorithms

3. Dynamic Programming

4. Backtracking

5. Probability algorithm

 

After an algorithm is designed, how can we know how efficient it is? Of course, we can't get it to the machine and run it again. Besides, even if we get it to the machine, it's because of the machine configuration and so on, the efficiency is also different. Therefore, we need to verify the efficiency of an algorithm by using the prior estimation method. The quality of an algorithm depends on two aspects: Time and Space. Therefore, the complexity of an algorithm is divided into time complexity and space complexity. Here we will briefly introduce the time complexity, which can be analogous to the space complexity.

The Code is as follows:

For (int A = 0;! = Num1; A ++)

{
For (INT B = 0; B! = Num2; B ++)
{
Num [a] [B] = B;
}
}

The code above contains nested loop statements, so the time complexity is O (num1 * num2 ).

 

The code of the half-lookup algorithm is as follows:

Node * Find (const type & X, node * PTR)
{
If (PTR = NULL)
{
Return NULL;
}
Else if (x <PTR-> data)
Return find (x, PTR-> leftchild );

Else if (x> PTR-> data)
Return find (x, PTR-> rightchild );

Else return PTR;
}

 

This function is recursive. The time complexity of the algorithm is O (log2n ).

The time complexity of common programs is as follows:

 

 

 

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.