Data structure and algorithm-overview

Overview

1. Data structure overview:

1. What is the data structure:

Data structure is defined by the presence of one or more of the mutual relationship between data elements of the set and between the data elements in the set relationship composition.

2. Data storage structure:

  • Sequential storage: Sequential storage structure: the data elements are stored in storage units with consecutive addresses, and the logical and physical relationships between the data are consistent . Array is a typical representative of sequential storage structure.

  • Chain storage: Chain storage structure: It stores data elements in any storage unit in the memory, that is, the data can be stored in various locations in the memory. The addresses of these data in the memory can be continuous or discontinuous .

The difference between the two:

For example, it’s like eating in the cafeteria

3. The logical structure of the data:

  • Collection structure: The data elements in the collection structure belong to the same collection, and they are in a juxtaposed relationship , and there is no other relationship.

  • Linear structure: The elements in the linear structure have a one-to-one relationship . There is a relationship between data and data.

  • Tree structure: The elements in the tree structure have a one-to-many relationship.

  • Graphic structure: The elements in the graphic structure have a many-to-many relationship.

 Second, the overview of the algorithm

1. Definition of algorithm:

Ideas used to solve the problem

Refers to the accurate and complete description of the problem-solving scheme, a series of clear instructions to solve the problem, and the algorithm represents the systematic method to describe the strategy mechanism of solving the problem .

2. The characteristics of the algorithm:

  1. enter
  2. Output
  3. Infinite: In a limited number of steps, results can be executed, but not unlimited.
  4. Determinism: There is only one definite result for an input, and it cannot result in 1 and 2 at a time.
  5. Feasibility: Able to solve practical problems.

3. The basic requirements of the algorithm:

  1. Correctness
  2. readability
  3. Robustness
  4. Time complexity: the time occupied by the algorithm and the speed of operation.
  5. Space complexity: the memory and resources occupied by the algorithm when it is running.

4.demo

Increase from 1 to 100: There is no best algorithm, only the most suitable.

package dataStruct;

public class AddOneToHandred {

	public static void main(String[] args) {
		int total=0;
		int end=100;
		
		//使用FOR循环
		for(int i=1;i<=100;i++) {
			total+=i;
		}
		
		//直接计算
		total=(1+end)*(end/2);
		
		System.out.println(total);
	}

}

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Qmilumilu/article/details/86750090