Basic notes on data structure 1: introduction and abstract data types

Keywords: data structure

Basic concepts and terms

  • Data is the symbolic representation of objective things;
  • Data element is the basic unit of data;
  • Data item is the smallest indivisible unit of data. A data element can be composed of several data items;
  • A data object is a collection of data elements with the same properties and a subset of data;
  • A data structure is a collection of data elements with one or more specific relationships

Data structures can be divided into two categories according to logical structure: linear structure and nonlinear structure, and can also be subdivided into four basic structures: set, linear structure, tree structure and graph structure.

The formal definition of data structure is: data structure is a binary
D a t a   S t r u c t u r e = ( D , S ) Data\ Structure = (D, S) Data Structure=(D,S)
Where D is the finite set of data elements and S is the finite set of relations on D.

The representation of data structure in computer (also known as image) is called the physical structure of data, also known as storage structure. It includes the representation of data elements and relationships.

There are two different representations of the relationship between data elements in the computer: sequential image and non sequential image. From this, two different storage structures are obtained: sequential storage structure and chain storage structure.

  • The characteristic of sequential mapping is to represent the logical relationship between data elements by means of the relative position of elements in memory
  • The characteristic of non sequential image is to express the logical relationship between data elements by means of pointers indicating the storage address of elements

A data type is a collection of values and a set of operations defined on the value set.

Abstract data type

Abstract Data Type (ADT) refers to a mathematical model and a set of operations defined on the model.

  • Atomic type: the value of a variable of atomic type is not decomposable
  • Fixed aggregation type: the value of a variable of this type consists of a certain number of components in a certain structure
  • Variable aggregation type: the number of components that make up the variable aggregation type value is uncertain

Abstract data types can be represented by the following triples:
( D , S , P ) (D,S,P) (D,S,P)
Where D is the data object, S is the relationship set on D, and P is the basic operation set on D.

ADT Abstract data type name {
	Data object:<Definition of data object>
	Data relationship:<Definition of data relationship>
	Basic operation:<Definition of basic operations>
} ADT Abstract data type name

Basic operation name (parameter table)
	Initial conditions:<Initial condition description>
	Operation result:<Operation result description>

There are two parameters for basic operations: assignment parameters only provide input values for operations; The reference parameter starts with & and will return the operation result in addition to providing the input value.

(1) Predefined constants and types

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
// Status is the type of function and its value is the result status code of the function
typedef int Status

(2) The representation (storage structure) of the data structure is described by a typedef. The data element type is agreed to be ElemType, which is defined by the user when using the data type

(3) The algorithms of basic operations are described by the following forms of functions

Function type function name (function parameter table){
	// Algorithm description
	Statement sequence
} // Function name

(4) Assignment statement

Simple assignment variable name = expression;
Concatenation assignment variable name 1 = Variable name 2 = ... = Variable name k = expression;
Group assignment (variable name 1), ..., Variable name k)= (Expression 1, ..., expression k);
		 Structure name = Structure name;
		 Structure name = (Value 1, ..., value k);
		 Variable name[] = expression;
		 Variable name[Starting subscript, ..., Termination subscript] = Variable name[Starting subscript, ..., Termination subscript];
Swap assignment variable names<->Variable name;
Conditional assignment variable name = Conditional expression ? expression T : expression F;

(5) Select statement

Conditional statement 1 if(Expression) statement;
Conditional statement 1 if(Expression) statement;
		  else(Expression) statement;
Switch statement 1 switch((expression){
		  case Value 1: Statement sequence 1; break;
		  ......
		  case value n: Statement sequence n; break;
		  default: Statement sequence n+1;
		  }
Switch statement 1 switch((expression){
		  case Condition 1: Statement sequence 1; break;
		  ......
		  case condition n: Statement sequence n; break;
		  default: Statement sequence n+1;
		  }

(6) Circular statement

for sentence		 for(Sequence of initial valued expressions; condition; Modify expression sequence)sentence;
while sentence	 while(condition)sentence;
do-while sentence do {
				Statement sequence;
			 }while(condition);

(7) End statement

Function end statement return expression;
			 return;
case End statement break;
Abnormal end statement exit(Exception code);

(8) Input and output statements

Input statement scanf([Format string], Variable 1, ..., variable n);
Output statement printf([Format string], Expression 1, ..., expression n);
// Format strings are usually omitted

(9) Notes

Single-Line Comments  // Text sequence

(10) Basic function

Find the maximum value		max(Expression 1, ..., expression n);
Find the minimum value		min(Expression 1, ..., expression n);
Find absolute value		abs(expression);
Less than integer value floor(expression);
Carry integer value ceil(expression);
End of judgment file eof(File variable)or eof
 End of decision line	eoln(File variable)or eoln

(11) Logical operation

And operation && : about A&&B,When A When the value of is 0,No longer right B evaluation
 Or operation || : about A||B,When A When the value of is not 0,No longer right B evaluation

Algorithm and algorithm analysis

Algorithm is a description of the solving steps of a specific problem.
Five important features:

  • Boundedness: the algorithm ends after a finite step, and each step is completed in a finite time
  • Certainty: each instruction in the algorithm has a precise meaning
  • Feasibility: a finite number of implementations can be performed through the basic operations that have been implemented
  • Input: there are zero or more inputs
  • Output: there are zero or more outputs

The algorithm design shall achieve:

  • Correctness
  • Readability
  • Robustness
  • Efficiency and low reserve demand

Time complexity: T ( n ) = O ( f ( n ) ) T(n) = O(f(n)) T(n)=O(f(n))
Space complexity: S ( n ) = O ( f ( n ) ) S(n) = O(f(n)) S(n)=O(f(n))
Time complexity estimation: inner cycle time complexity * outer cycle time complexity

Posted by deeessay on Thu, 18 Nov 2021 21:47:19 -0800