Current location - Training Enrollment Network - Mathematics courses - What is data structure and its relationship with algorithm?
What is data structure and its relationship with algorithm?
I am a data fan. On the road of computer, I am also a data structure enthusiast. Now I am obsessed with databases when I am developing with my classmates in college. Let me talk to you about my personal understanding: first of all, data structure is a basic subject of computer linguistics, which does not belong to any language, and almost all standard languages reflect the idea of algorithm. There are some ambiguities in the above concepts. Now let's talk about it in detail. I believe your data structure is described in a specific language, such as C/C++. That's to help you learn the data structure, which doesn't belong to any language (I believe you can't just type the program in the book into the computer, it just describes the process, and you need to modify and add something to debug the program). You should pay attention to the concepts of physical storage structure/logical storage structure of data from the beginning of your book, and explain that data structure is "data structure" from the beginning, and the storage method in memory is physical storage structure, which is logical in the eyes of program users. For example, if you study the linked list in C/C++, what is the concept of linked list? You use the pointer system to connect the first address of the next node to form one. This is just a concept for programmers, but what is the way to store it in memory? For you programmers, this is "transparent", its internal allocation space is random, and there is no line in memory to connect them in series. So this is a physical and logical concept, and we programmers only need to know these, and the main thing we want to study is "logical structure". I can give you a concept summarized by myself: all algorithms must be based on data structure to survive. That is to say, for any algorithm, it must rely on an existing data structure to operate it, and the data structure becomes the operation object of the algorithm, which is why the two categories of algorithm and data structure are not separated, and the algorithm is meaningless without data structure; And a data structure without an algorithm is a corpse without a soul. It is estimated that this may be a little dizzy for beginners of algorithm. Let's be specific: What is the simplest thing in our data structure? I personally make the linear table in the book more detailed (here for better understanding): a single element, such as: int I;; This I is a data structure, what kind of data structure it is, that is, a variable of type int, and we can perform a series of operations on it, such as addition/subtraction/multiplication/division/self-addition. Of course, it is meaningless for us to study the data structure and algorithm of a single element, because it is atomic in nature and may have small differences in some specific operations. But to upgrade to a higher level: our linear table (generally including: sequential table/linked list), then what is the main purpose of our research on these two data structures? Generally, we mainly study their four operations based on structure (that is, nodes), namely, add/delete/modify/search (query) (why there is such an operation, which I will talk about below), and we generally call it "add/delete/modify" as an update. For a node, if you want to update operations such as deletion, you will use the subscript access method of the order table. Then after deleting an element, we need to move all the elements after this element forward. This time is long for a long sequence table, but for a linked list, there is no concept of sequence. To delete an element, we only need to point the pointer of the previous node to the next node of the deleted point, use the free () function to free up space and restore to the operating system. When performing retrieval operation, the sequence table directly uses subscripts for random access, while the linked list needs to access the matched elements from the beginning to get the used elements, which is also proportional to the number of nodes in the linked list. Therefore, each of our data structures will produce different effects for different algorithms. Each algorithm is neither absolutely good nor absolutely bad, and has its own application value and methods. In this way, in the actual project development, we can comprehensively evaluate the internal algorithm time and space and the hardware capabilities that the project can provide, thus making our algorithm better. (Only one aspect based on data structure is mentioned here: speed. In fact, the elements of the algorithm should also include: stability, robustness, correctness, finiteness, understandability, input and output, etc. Why do you want to do these messy operations in the form of nodes? First of all, a clear procedural programming language provides some basic first information, such as some keywords/reserved words/operators/separators. We need programs to solve real-life problems. For example, we need programs to record the personnel changes in a company, so the data types of personnel are not available in the programming language, so we need to define the internal information of personnel (it can't be complete, only those we need), such as age/gender/name/date of birth/nationality/work unit/title/salary status. Then we can use some c ./* age variables to express the age of people in the company. */Similarly, we have made other definitions. We use structures or classes to encapsulate them into user-defined data types or classes, so as to define a person's object, which contains a lot of template data. According to my personal experience, I estimate that the amount of code should be within 10000 (my personal manager: I just suggest starting with your first line of code, no matter whether the program is correct or not, no matter what language, as a standard programmer, you need to have the basic knowledge of100000 lines of code (this is the approximate data I felt at some time in my sophomore year, and others may not be suitable).