Overview of Java data structures and algorithms (1)

We know that program = data structure + algorithm, then, what is a data structure, and what is an algorithm? How to systematically learn data structures and algorithms?

(1) Why do we need to learn data structures and algorithms?

Data structure (data structure) is a discipline that studies the way of organizing data. Data is the carrier of information. When a lot of information is combined, we need to consider how to organize information effectively. Adding, deleting, modifying and checking data, the algorithm is used to describe the problem and the way of thinking or way of solving the problem, in simple terms, it is the step of solving the problem.

Encountered a practical problem, two things need to be solved:

(1) What data information is involved in the question;

(2) What strategy is used to solve the problem.

The former is a data structure, and the latter is an algorithm. Data is the sum of all the information that can be input to the computer, structure refers to the relationship between data, and data structure is to effectively store data and the relationship between them in the computer. How to store the problem in the data in the computer, make it usable, and become organized and effective usable information, that is, the task of data structure, when facing the problem, how to solve it, that is, the solution method and steps, that is the algorithm . Algorithm refers to a description of the steps to solve a specific problem. To put it plainly, it is a method and strategy to solve the problem.

Only data structure without algorithms is equivalent to storing data in a computer without effective methods for processing. It is like an unfinished building with only frames; if there are only algorithms and no data structures, it is like a mirage in the desert. It's just a castle in the sky.

Encounter a practical problem, make full use of the data structure learned, effectively store the data and the relationship between them in the computer, and then select the appropriate algorithm strategy, and use the program to implement it efficiently. , This is what Professor N. Wirth said: data structure + algorithm = program .

Take programming as an example:

 Programming is like a car, and the data structure and algorithm are the gearbox inside the car. A person who does not understand the principle of a gearbox can drive a car, and a person who does not understand data structures and algorithms can also program. But if a driver understands the principle of a gearbox, such as reducing the speed to get more traction, or reducing the traction to get a faster driving speed. Then use the first gear when climbing, you can get more traction; when going downhill, use the low gear to limit the driving speed of the car. Back to programming, for example, if you want to temporarily store the names of students in a class in memory, what data structure do you choose to store, array or ArrayList, or HashSet, or other data structure. If you don’t understand the data structure, you may choose a container to store it, and you can complete all the functions. However, if the amount of student data increases in the later period, the randomly selected data structure will definitely have performance problems, and the one who understands the data structure and The algorithm person will choose the appropriate data structure to solve the corresponding problem in the actual programming, which will greatly improve the performance of the program.   

It is true that people who do not understand data structures and algorithms can also program, but those who are familiar with data structures and algorithms can program better.

The data structure and algorithm knowledge system are as follows:

ç¥è¯ä½ç³»

(2) Introduction to data structure

   For the data structure, there are one-to-one, one-to-many, and many-to-many relationships. Common data structures are as follows:

 

Generally speaking, data structures are divided into linear structures and non-linear structures. Common linear structures are: arrays, queues, linked lists, and stacks. Non-linear structures include: two-dimensional arrays, multi-dimensional arrays, generalized tables, tree structures, and graph structures.

     

   Whenever data is involved, the operation of the data will be considered, that is, addition, deletion, modification, and checking. The time complexity and space complexity of the operation are one of the consideration criteria for which data structure we consider to use.

Comparison of the advantages and disadvantages of common data structures:

 

(3) Introduction to the algorithm

Algorithms, as the name suggests, are the steps to solve the problem. Then, how should we measure the quality of the algorithm between the solution to different problems and the different methods of the same problem? Three scales to measure the superiority of an algorithm: space complexity, time complexity, and stability.

Space complexity: One sentence to understand is the additional storage space this algorithm consumes when the scale is n.

Time complexity: To understand in one sentence, the number of executions of sentences in an algorithm is called sentence frequency or time frequency when the scale of this algorithm is n.

Stability: Mainly to describe the algorithm. After each execution, the result is the same, but it can be entered in a different order, and the time complexity and space complexity may be different.

  Five characteristics of the algorithm: finiteness, determinism, input and output, and feasibility.

  •   有穷性:对于任意一组合法输入值,在执行又穷步骤之后一定能结束,即:算法中的每个步骤都能在有限时间内完成。
  •   Determinism: The operations that should be performed in each case are specified in the algorithm, so that the executor or reader of the algorithm can clarify its meaning and how to perform it. And under any conditions, the algorithm has only one execution path.
  •   可行性:算法中的所有操作都必须足够基本,都可以通过已经实现的基本操作运算有限次实现之。
  •   With input: the value of the object processed by the algorithm, usually embodied in a group of variables in the algorithm. Some input quantities need to be input during the execution of the algorithm, and some algorithms may have no input on the surface, but are actually embedded in the algorithm.
  •   有输出:它是一组与“输入”有确定关系的量值,是算法进行信息加工后得到的结果,这种确定关系即为算法功能。

Common algorithms are: recursion, sorting, binary search, search, hashing, greedy, divide and conquer, backtracking, dynamic programming, string matching

Some well-known algorithms:

⒈Divide and divide: the oldest algorithm in the known world

⒉Cutting circle technique: pioneered by Liu Hui, improved by Zu Chongzhi, and calculated pi

⒊Qin Jiushao algorithm: greatly simplify the calculation of polynomials

⒋Quick sort algorithm: one of the top ten algorithms in the 20th century

⒌Huffman coding: the basic algorithm of data compression

⒍RSA encryption: the basis of modern computer network data encryption algorithms

⒎Monte Carlo search tree algorithm: the basic algorithm of artificial intelligence, an algorithm that allows computers to "think like humans"

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_41792162/article/details/109898936