Textbook-Extracurricular books recommended
Gao Yifan (pseudo algorithm → true code)
Data Structure Overview
Defined
How do we store large and complex problems in real life in a specific data type and a specific storage structure into the main memory (memory), and on this basis for the implementation of a function (such as finding an element, delete an element, sorting all elements), the corresponding operation is called the algorithm
Data structure = individual + individual relationship
Algorithm = operation on stored data
Algorithm
Methods and steps for solving problems
Criteria for measuring algorithms
1. Complexity of Time
The approximate number of times the program will be executed, not the time it takes to execute
2. Complexity of space
The maximum memory occupied by the algorithm during execution
3. Degree of difficulty
4. Robustness
The status of data structures
Data structure is the core course in software
Program = data storage + data manipulation + languages that can be executed by the computer
Last edited on August 18, 2015, 23:10:06
Pre-knowledge
Pointer
The importance of pointers:
Pointer is the soul of C language
Defined
Address
The address is the number of the memory unit
Non-negative integer starting at 0
Range: 0--ffffffff (0--4g-1)
Pointer:
The pointer is the address, the address is the pointer
A pointer variable is a variable that holds the address of a memory cell
The essence of a pointer is a non-negative integer with restricted operation
Classification:
1. Basic types of pointers
2. Pointer and array relationships
Last edited on August 19, 2015, 23:06:51
Structural body
Why is there a struct
In order to represent some complex data, the common basic type variable does not meet the requirements
What do you mean, structural body
Structs are composite data types that users define themselves according to their needs
How to use the structure body
Two different ways
struct Student st = {, "Zhangsan", 20};
struct Student * PST;
1.
St.sid
2.
Pst->sid
This member of the SID in the struct variable that the PST points to
Precautions
struct variables cannot be subtraction, but can be assigned to each other
Common structure variables and structure pointer variables as function-parameter-transfer problems
Use memory---across functions to implement with dynamic memory allocation
In general, the memory is freed after the custom function ends, and only the dynamically allocated memory does not meet the free function, and the custom function ends, but the memory still exists.
Last edited on August 20, 2015, 23:00:44
Module one: linear structure [put all the nodes in a straight line]
continuous storage [Array]
1. What do you call an array
Same element type, same size
2. Advantages and disadvantages of arrays
discrete storage [Linked list]
Defined:
N Nodes Discrete distribution
Connect to each other by pointers
Each node has only one precursor node, and each node has only one subsequent node
The first node has no precursor, and the tail node has no subsequent nodes.
Professional terminology:
First node:
First valid node
Tail Node:
Last valid node
Head node:
The head node is the same as the data type and the first node type.
The node before the first valid node
The head node does not hold valid data.
The main purpose of the head node is to facilitate the operation of the linked list.
Head pointer:
Pointer variable pointing to the head node
Tail Hands:
Pointer variable pointing to tail node
If you want to work with a linked list through a function, we need to accept at least what information is linked to the list:
Only one parameter is required: the head pointer
Because we can figure out all the other information in the list through the head pointer.
single-linked list
doubly linked list:
Circular link List
Can find all the other nodes through any node.
Non-circular linked list
Algorithm:
Traverse
Find
Empty
Destroyed
Request length
Sort
Delete a node
Inserting nodes
Algorithm:
The narrow algorithm is closely related to how data is stored.
The generalized algorithm is independent of the way data is stored
Generic type:
The effect of using a technology is: different storage methods, the same operation is performed
Chain list sorting algorithm
1 for(i=0,p=phead->pnext; i<len-1; ++i,p=p->pnext)2 {3 for(j=i+1,q=p->pnext; j<len; ++j,q=q->pnext)4 {5 if(P->data > Q->data)//similar to a[i in arrays] > A[j]6 {7t = p->data;//similar to the array: t = a[i];8P->data = q->data;//similar to the array: a[i] = a[j];9Q->data = t;//similar to a[j in an array] = t;Ten } One } A}
re-discussion on data structure
Narrow:
data structure is a special study of the problem of storage
The storage of data consists of two aspects: individual storage + individual relationship storage
Generalized:
Data structures contain both the storage and the manipulation of data
The operation of storing data is the algorithm
algorithm:
narrowly
algorithms are closely related to how data is stored
Generalized
the algorithm is independent of how the data is stored
that's the idea of generics .
There are several storage structures for data
Linear
continuous storage of "arrays"
Advantages
Fast Storage Speed
Disadvantages
the length of the array must be known beforehand
Insert Delete element is slow
space is usually limited.
chunks of contiguous blocks of memory are required
very inefficient insertion and deletion
Discrete storage "linked list"
Advantages
No space restrictions
Insert Delete element soon
Disadvantages
Very slow access speed
Application of linear structure--stack
Application of linear structure--queue
Nonlinear
Tree
Figure
List of advantages and disadvantages:
One of two common applications for linear structures stack
Defined
A kind of storage structure that can realize "advanced out"
Stacks similar to Chests
Classification
Static stack
Dynamic stacks
Algorithm
Out of the stack
Press Stack
Application
Two common applications of linear structures in the second queue
Defined:
A storage structure that enables "FIFO"
Classification:
Chained queues--implemented with linked lists
Static queue--implemented with arrays
A static queue must always be a circular queue
Explanation of the circular queue:
1. Why does a static queue have to be a circular queue?
2. The loop queue requires several parameters to determine
Requires 2 parameters to determine
Front
Rear
3. Meaning of each parameter of the cyclic queue
2 parameters different occasions have different meanings
It is recommended that beginners remember first and then slowly experience
1). Queue initialization
Both the font and rear values are zero
2). Queue non-empty
The font represents the first element of a queue
Rear represents the next element of the last valid element of a valid element of a queue
3). Queue Empty
The values of the font and rear are equal, but not necessarily zero
4. Circle team included in the team pseudo algorithm explanation
Two steps to complete:
1. Place the value in the location represented by R
2. Wrong wording rear = rear + 1;
The correct wording is: Rear = (rear + 1)% of the length of the array
5. Circle Team list The team pseudo algorithm explained
Front = (front+1)% length of array
6. How to determine if the loop queue is empty
If the values of front and rear are equal,
Then the queue must be empty
7. How to determine if the loop queue is full
Pre-Knowledge:the value of front may be larger than rear,the value of front may also be smaller than rear,of course, it could be equal .two different ways1. Add one more table identification parameter2. Use less of one element [usually the second way]if R and F values are next to each other, the queue is fullThe C-language pseudo-algorithm means: if ((r+1)% array length ==f) is fullElsedissatisfaction
dissatisfactionQueue AlgorithmQueueout Teamspecific applications for queues:all time and related operations have a shadow of the queue topic: RecursionDefinition:a function calls itself directly or indirectly recursion satisfies three conditions1. Recursion must have a definite termination condition2. The size of the data processed by the function must be decremented3. This conversion must be solvable Loops and recursionrecursion:Easy to understandSlow SpeedLarge storage spaceLoop:Not easy to understandFast SpeedSmall Storage space Example: 1. Finding factorial2.1+2+3+4+ ... 100 of and3. Hanoi4. Walk the Maze
Data structure note (Hao Bin presenter) (2015-11-8 00:57:45 Update)