Linear table of data structure and algorithm (on)

It is recommended to pay attention to the collection and continue to update...

1. Definition of linear table

The definition of a linear table: a finite sequence (sequence predecessor and successor) composed of zero or more data elements with the nature of a line like a queue. (There is only one)

Mathematical definition: If the linear expression is denoted as (a1,...,ai-1,ai,...an), then ai-1 is ahead of ai, and ai is ahead of ai+1 in the table. Calling ai-1 is the direct of ai The precursor element, ai+1 is the immediate successor element of ai.
Therefore, the number of elements in the linear table n (n>=0) is defined as the length of the linear table. When n=0, it is called an empty table.

2. Abstract data types

Data type: refers to a collection of values ​​of the same nature and a general term for some operations defined on this collection.

Atomic type: A basic type that can no longer be decomposed. For example, integer.
Structure type: It is composed of several types and can be decomposed. For example, arrays.

Abstraction: refers to extracting the universal essence of things. It requires extracting the characteristics of the problem and ignoring the non-essential details, which is a generalization of specific matters. Abstraction is a way of thinking about problems, it hides complex details.

Abstract data type (ADT): Refers to a mathematical model and a set of operations defined on the model.

The definition of an abstract data type depends only on its set of logical characteristics, and has nothing to do with how it is represented and implemented inside the computer.

The meaning of abstraction lies in the mathematical abstraction of data types.

3. Standard format of abstract data types:

ADT abstract data type name

Data
defining logical relationships between data elements (one to one relationship between elements)

Operation
: initList(*L): Initialize the operation and create an empty linear list L.
ListEmpty(L): Determine whether the linear list is empty. If the linear list is empty, return true, otherwise it returns false.
ClearList(*L): Clear the linear list.
GetElem(L,i,*e): Return the value of the i-th position element in the linear table L to e.
LocateElem(L,e): Find the element equal to the given value e in the linear table L, if you find Success, return the sequence number of the element in the table to indicate success; otherwise, return 0 to indicate failure.
ListInsert(*L,i,e): Insert a new element e at the i-th position in the linear list L.
ListDelete(*L,i,*e): Delete the i-th position element in the linear table L, and return its value with e.
ListLength(L): Returns the number of elements in the linear list L.

EndADT

4. The storage structure of the linear table

The sequential storage structure of the linear table: through the form of placeholder, the sequential storage in the memory space actually encapsulates the array, adding a variable of the current length. (Start position, maximum storage capacity, current length)

The sequential storage structure of the linear table, when storing or reading data, no matter where it is, the time complexity is O(1). When inserting or deleting, the time complexity is O(n). It shows that the number of suitable elements is relatively stable.

Advantages:
(1). There is no need to add extra storage space to express the logical relationship between the intermediate elements.
(2). You can quickly access elements at any position in the table.
Disadvantages:
(1). Insert and delete operations need to move a large number of elements.
(2). When the length of the linear table changes greatly, it is difficult to determine the storage space capacity.
(3). It is easy to cause "fragmentation" of storage space.

The chain storage structure of the linear table: A group of arbitrary storage units are used to store the data elements of the linear table. This group of storage units can be stored in any unoccupied location in the memory. Compared to the sequential storage structure, each data element only needs to store one location. Now in the chain storage structure, in addition to storing the data element information, the storage address (pointer) of its successor element is also stored. That is to say, in addition to storing its own information, it is also necessary to store a piece of information indicating the storage location of its immediate successor.

The domain that stores the data element information is called the data domain , and the domain that stores the immediate subsequent position is called the pointer domain . The information stored in the pointer field is called a pointer or chain . These two parts of information form a data element called a stored image , which is called a node . The n nodes are linked into a linked list, which is the chain storage structure of the linear list. Because each node of this linked list contains only one pointer field, it is called a singly linked list .

For a linear table, there must be a head and a tail, and the linked list is no exception. We call the storage location of the first node in the linked list the head pointer, and the last node pointer is NULL (NULL)

Note: Welcome to join the qq group to exchange and learn.

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45823731/article/details/113093853