Data structures and algorithms, data structure Algorithms
What is a data structure?
The data structure is divided into data and structure. Numbers, characters, graphics, and sounds are all data. The structure is divided into logical structure and storage structure. The logical structure is the abstract relationship between data. The storage structure is the storage of data in computer memory (memory, disk. Data structure studies how data is stored in computers. Data structures include arrays, stacks, binary trees, and hash tables.
What is an algorithm?
Algorithms are the process of processing a given problem in a computer. To put it bluntly, they process data in a data structure, such as sorting and searching data.
What is the relationship between data structures and algorithms?
The data processing process of a computer: Data Input --> Computer Processing-> data output
It is important to organize raw data and store it in a computer to facilitate space saving and computer processing. It is also important to select appropriate algorithms to improve the efficiency and reliability of solving problems, it cannot be discussed in isolation.
Algorithms can only play a role in an appropriate data structure. Different data structures affect algorithm selection and efficiency.
Some scientists concluded that algorithm + Data Structure = Program
What are the functions of data structures and algorithms?
After learning about the previous concepts, let's take a look at the application scenarios.
Real Data Storage:
Store physical and physical data outside the computer in the real world. For example, a personnel file records the information of a real person.
Programmer tools:
The chain table, stack, queue, and other structures are used as tools to simplify other operations.
Modeling the Real World:
Construct a model for the real world using a data structure. It is used to represent the routes and circuit connections between cities.
Get a general understanding of the features of the data structure:
Data Structure |
Advantages |
Disadvantages |
Array |
Fast insertion and quick access to subscripts |
Slow query, slow deletion, fixed size |
Ordered array |
Faster than searching unordered Arrays |
Slow insertion and deletion, fixed size |
Stack |
Back-to-first-out access |
Slow access to other items |
Queue |
First-in-first-out access |
Slow access to other items |
Linked List |
Fast insertion and Deletion |
Slow Query |
Binary Tree |
Fast insertion, deletion, and search (such as balance between fruit trees) |
Complex deletion Algorithms |
Red-black tree |
Insert, delete, and search are fast (the tree is always balanced) |
Complex algorithms |
2-4-4 trees |
Insert, delete, and search are fast (the tree is always balanced). Similar trees are useful for disk storage. |
Complex algorithms |
Hash table |
If the keywords are known, the access speed is extremely fast and the insertion speed is fast. |
Slow deletion, unknown keywords, slow storage, insufficient disk space utilization |
Heap |
Fast insertion and deletion, fast access to the largest data item |
Slow access to other data items |
Figure |
Real-world Modeling |
Some algorithms are slow and complex. |
In addition to arrays, the above are called abstract data structures (ADT ).