Data structure and algorithm (Chapter 1): What is data structure and algorithm

I wonder if you have such doubts? Why do they always appear at the same time when talking about data structures or algorithms? Shouldn't these be two courses? Why integrate it together?

Next, we will take a question to understand the relationship between data structure and algorithm.

1. The relationship between data structure and algorithm

What is a data structure? What is an algorithm?

You can definitely get a bunch of results when you go to Baidu, but the results of these searches are not understandable at all. The so-called definition is to say that the question that everyone can understand is a word that no one can understand.

In fact, this is no way. In order to make the definition clear and rigorous, many restrictions must be added so that the definition will not be ambiguous, but the result of this is that no one can understand it.

Below we try to restore the most essential meaning of data structures and algorithms, concepts that can be understood by everyone.

Data structure refers to the storage method of a group of data.

Algorithm refers to a method of manipulating this set of data.

for example:

The library collection of books is generally stored according to the category and number of the book, and this storage method is the data structure.

So how do we find one of these books? There are many ways, you can start by entering the door and look up one by one. It can also be computer, humanities, science, literature, economics according to the category and number of the book. . . To locate the bookshelf, and then look for them one by one. This method of finding books is an algorithm.

Next, we can answer the question we asked at the beginning. Why do they always appear at the same time when it comes to data structures or algorithms?

This is because data structures and algorithms are complementary to each other. The data structure serves the algorithm, and the algorithm should act on a specific data structure. Therefore, we cannot isolate the data structure in terms of algorithms, nor can we isolate the algorithm in terms of data structures.

Second, the classification of data structure

Data structure can be divided into logical structure and physical structure from a large level . Logical structure refers to the relationship between data elements. The physical structure refers to the way data is stored on the disk.

Logical structure

  • Collection structure

  • Linear structure

  • Tree structure

  • Graphic structure

Physical structure

  • Sequential storage

  • Chain storage

Three, code implementation

Essentially learning data structures and algorithms can ignore the language, because all programming languages ​​can be implemented. But it is strongly recommended to use C语言the algorithm to achieve, because C语言you can make you a deeper understanding of the data in memory is how the store. When you C语言then have a certain understanding, you will find what others are spicy chicken, only C语言writing is succulent, C语言always drops of God ~

Guess you like

Origin blog.csdn.net/yilovexing/article/details/106945989