Data structure:
is a collection of data elements that have one or more specific relationships with each other
1. Basic Concepts and Terminology
2. Logical structure and physical structure
2.1 Logical structure
Refers to the relationship between data elements in a data object.
1. Collection structure
Individual data elements are equal.
2. Linear structure
The data element relationship of the linear structure is one-to-one.
3. Tree structure
The data element relationship of the tree structure is one-to-one.
4. Graphic structure
The data elements of the graph structure are many-to-many relationships
When we use schematic diagrams to represent the logical structure of data, we should pay attention to two points:
Think of each data element as a node, represented by a circle.
The logical relationship between elements is represented by the connection between the nodes. If the relationship is directional, it is represented by the connection with the arrow.
2.2 Physical structure
Physical structure: refers to the storage form of the logical structure of data in the computer.
There are two storage structures for data elements: sequential storage and chain storage.
1. Sequential storage structure
Sequential storage structure: data elements are stored in storage units with continuous addresses, and the logical and physical relationships between the data are consistent.
2. Chain storage structure
Chained storage structure: store data elements in any storage unit. This group of storage units can be continuous or discontinuous. The storage relationship of data elements does not reflect its logical relationship, so a pointer is needed The address of the data element is stored, so that the location of the associated data element can be found through the address.
3. Abstract data type
3.1 Data types
Data type: refers to the general term for a set of values with the same nature and some operations defined on this set.
3.2 Java basic data types
Basic data types include boolean (Boolean), float (single-precision floating point), char (character), byte (byte), short (short integer), int (integer), long (long integer) ) and double (double-precision floating-point type) in total 8 types.
type name | keywords | used internal memory | Ranges |
---|---|---|---|
Byte | byte | 1 byte | -128~127 |
short integer | short | 2 bytes | -32768~32767 |
integer | int | 4 bytes | -2147483648~2147483647 |
long integer | long | 8 bytes | -9223372036854775808L~9223372036854775807L |
single precision floating point | float | 4 bytes | +/-3.4E+38F (6~7 effective digits) |
double precision floating point | double | 8 bytes | +/-1.8E+308 (15 significant digits) |
character type | char | 2 bytes | ISO single character set |
Boolean | boolean | 1 byte | true or false |
3.3 Java reference data types
Reference data types build on primitive data types, including arrays, classes, and interfaces. Reference data types are defined by users to restrict other data types.
Reference types also have a special null type. The so-called reference data type is a reference to an object, the object includes two kinds of instances and arrays. In fact, a reference type variable is a pointer, but the term pointer is no longer used in the Java language.
A null type is the type of the null value, which has no name. Since the null type has no name, it is not possible to declare a variable of the null type or to convert to the null type.
A null reference (null) is the only value for a variable of type null. An empty reference (null) can be converted to any reference type.
In actual development, programmers can ignore the null type, assuming that null is just a special literal of the reference type.
Note: A null reference (null) can only be converted to a reference type, not to a basic type, so do not assign a null value to a variable of a basic data type.
3.4 Abstract data types
The abstract data type Abstract Dataη ADT refers to a mathematical model and a set of operations defined on the model.