# Data structure in embedded system software design

## Chapter I

**Hash storage**: directly calculate the storage location of the data element according to the keyword of the data element. The basic idea is: take the keyword K of the data element as the independent variable, calculate the corresponding function value through a determined function relationship (hash function), take this value as the storage address of the data element, and store the data element in the storage location indicated by the address.

**Characteristics of algorithm**: finiteness, certainty, feasibility, input and output;

The high efficiency of the algorithm is reflected in that the execution time of the algorithm should be as short as possible and the occupation of storage space should be as small as possible, that is, it can save time and space.

Algorithmic**Time complexity**， \(T(n) = O(f(n))\)

In general, f (n) is the sum of algorithm execution times**Same growth rate**(understood as the fastest rising function term in the expression of algorithm execution times) for the function of N, special case, there are three statements for exchanging two variable values:

`temp = i; i = j; j = temp;`

The execution time is a constant independent of N, and the time complexity of the algorithm is a constant order, then\(T（n） = O(1)\)

Algorithmic**Spatial complexity**

The storage space of the algorithm refers to the maximum storage space required during the execution of the algorithm. The storage space needed in the implementation of the algorithm includes three parts: the space occupied by the input data; The space occupied by the program itself (there will be no great difference between different algorithms);**Space occupied by auxiliary variables and additional space occupied**(key analysis); The space complexity of the algorithm is defined as:\(S（n）= O(g(n))\), as the scale of the problem increases, the space growth rate and\(g(n)\)The growth rate is the same.

The popular definition of embedded system is that it is a special computer system with application as the center, computer technology as the basis, software and hardware can be tailored to meet the strict requirements of application system on function, reliability, cost, volume and power consumption. The CPU of high-grade embedded system is more than 32 bits, and the information processing capacity is relatively large, but the price is expensive. The low-grade embedded system is less than 16 bits (mainly 8 bits), which is used more in production and is suitable for

- Small data scale and simple data structure（
**Linear table**） - Adopt algorithms that occupy less RAM resources (which may reduce algorithm efficiency and realize functions)
- Using the algorithm with simple program code can reduce the ROM overhead

## Chapter 2 linear table — the simplest and most commonly used linear structure

Linear table is\(n\)A finite sequence of data elements, denoted as（\(a_{1},a_{2},…,a_{n}\)）The basic operations include: empty table, length, node, location, insertion and deletion.

**Sequence table**

A sequential table is a logical sequence of nodes in a linear table（**The logical order is consistent with the physical order**）In general, all nodes in the linear table are of the same type, that is, each node occupies the same space. Before programming, a sufficient continuous memory space can be allocated in advance\(max * L\), where,\(L\)Is the size of the node,\(max\)Is the maximum number of nodes; For example, a sequence table is defined with a one-dimensional array and structure

`#define max 1024`

Sequential table**insert**Operation: (insert x at the ith node)

`int insert(sequencelist *L, datatype x, int i)`

Sequential table**delete**Operation: (delete the ith node)

`int delate(sequencelist *L, int i)`

The advantage of sequential table is that it can easily access any point in the table. However, in addition to its inconvenient operation and low operation efficiency, because its occupied space must be continuous space and the number of nodes is not fixed, it is difficult to determine the appropriate memory when allocating space in advance, which is easy to cause insufficient memory or memory waste.