(A) the basic concept

1. The data structure (data structure)

  1. Efficiency of the process to solve the problems with the organization of the relevant data
  2. Efficiency solutions to problems related to the efficiency with space
  3. Ingenious solutions to problems related to the degree of efficiency with the algorithm
#include <stdio.h>
#include <time.h>
clock_t start, stop;  //clock_t是clock()函数返回的变量类型
double duration;  //记录被测函数运行时间,单位:秒
int main(void)
{
	start = clock();  //clock():捕捉从程序开始运行到clock()被调用时所耗费的时间(单位:时钟打点)
	//测试算法
	stop = clock();
	duration = ((double)(stop - start)) / CLK_TCK;  //CLK_TCK:机器时钟每秒所走的时钟打点数(1000)
	printf("算法所用时间为%f秒\n",duration);
	return 0;
}

2. The three elements of the data structure

The logical structure data (logical structure)

  1. Linear structure: one to one relationship between the elements
  2. Structure Graphics: many to many relationships between elements
  3. Tree structure: one to many relationship between elements

Data storage structure (storage structure)

  1. Sequential storage structure: Data Element is the address section of contiguous space (array) in the memory
  2. Storage Structure: discrete data elements in the memory address, continuous (list) by logical pointer

Operational data (operation): data type allows operations (the completion of these operations is the algorithm used)

3. abstract data types (abstract data type)

type of data:

  1. Set of data objects
  2. Operation data set associated with a set

Abstract: Description of data types not dependent on the specific implementation method

  1. Regardless of the machine to store data
  2. Regardless of the physical structure of the data storage
  3. Nothing to do with algorithms to achieve operating and programming languages

4. The method (algorithm)

  1. A limited instruction set (Limitation)
  2. Accept some input (no need to enter in some cases)
  3. Generating an output (output to be generated)
  4. Certain termination (enforceable) after a limited step
  5. Each instruction must have a clear goal, not ambiguity, must be within the computer can handle it (certainty)

The measure of the merits of the algorithm

1. validity: the algorithm should meet the exact needs of the specific problems

2. Robustness: When you enter invalid data, the algorithm can make appropriate treatment

3. Readability: reading benefit others

4. The time complexity (time complexity) T (n) = O (f (n)): the program runs the length of time spent

  1. Extensive use of cycle
  2. Multiply and divide time consuming than addition and subtraction
  3. Usually analysis is generally the worst time complexity

The space complexity (space complexity) S (n) = O (f (n)): a program storage unit occupies when executed length

  1. A large number of recursive function calls
  2. Creating a large number of variables or objects

6. The complexity of the representation of the progressive

  1. T (n) = O (f (n) indicates the presence of a constant C> 0, n [0]> 0 such that if n> = n have T (n) <= C * f (n [0] time) (Function Upper Bound)
  2. O(1) < O(log n) < O(n) < O(nlog n) < O(n^2) < O(n^3) < O(2^n) < O(n!) < O(n^n)
  3. Complexity addition rule: T . 1 + T 2 = max (O (F . 1 ), O (F 2 ))
  4. Complexity Multiplication Rule: T . 1 * T 2 = O (F . 1 * F 2 )
  5. For a cycle time equal to the number of cycles multiplied by the complexity of the loop body code complexity
  6. The complexity of the structure if-else if the judgment conditions depending on the complexity and complexity of both the leg portions, overall complexity, whichever is the largest
Released two original articles · won praise 0 · Views 22

Guess you like

Origin blog.csdn.net/Rain_Poplar/article/details/104846264