Data Structures and Algorithms | Part One Lesson 1: What are Data Structures and Algorithms
Posted May 27, 2020 • 6 min read
"Data Structure and Algorithm" full series
2. What is an algorithm
3. Algorithms are everywhere
4. The "privileged" role of the computer
5. What is a data structure
6. The first part of the second lesson
Programmers should know:Program = Data Structure + Algorithm(Program = Data Structure + Algorithm).
As a programmer, if you don't understand the data structure and algorithm, you should go out and say hello to others.
In this course, I will take you from an introductory to a proficient data structure and algorithm in a step-by-step, relaxed and humorous form.
You will find that getting started with data structures and algorithms is actually not difficult at all.
Without further ado, we went directly to the topic.
2 . What is an algorithm
Algorithm English is Algorithm.
First let's think about a problem:
What is an algorithm?
It is not easy to answer this question accurately, but it is not so difficult. I do n t need to use a lot of theory to understand what an algorithm is, and the algorithm is not limited to IT(Information Technology for short, which means "information technology") Programming field.
So an easy-to-understand answer can be:
Algorithm is an accurate description of how to solve a problem in the form of a simple concept.
- Algorithm is a description(description), and is an accurate description.
- What does it describe? Describe how to solve the problem.
- In what form? In the form of simple concepts.
Speaking of problems, in daily life, we often need to solve problems. Some people may need to solve many problems every day, and some people may be the problem itself.
Next, I will describe a problem in life and consider the concepts of "problem" and "algorithm" in a broad sense.
3 . The ubiquitous algorithm
We can start with a question that concerns almost everyone:cooking. After all, "people take food as the sky."
Suppose you are hungry and you come to the kitchen and want to order something to eat. You happen to see a packet of instant noodles, and then you lick your tongue unconsciously. You want to eat instant noodles(if you happen to see this before going to bed , Please do n t hit me. Everyone is discouraged from eating more instant noodles. The example here can also be cooking rice, noodles or other foods), so how should you cook it?
This is a simple process(only the easiest way to boil it is mentioned here, please don't be entangled with the details of cooking, maybe you have other better ways to cook instant noodles):
- Pour the right amount of water into the pan
- Light a fire on the stove(if it's an induction cooker, you don't need a fire)
- Put the pot on the stove
- Wait for the water to boil and switch to medium heat
- Put the instant noodles into the pan
- Cook for half a minute
- Put in all seasoning packages
- Cook for 1 minute
- Out of the pot
As you can see, I have accurately described how to solve the problem of "cooking instant noodles" in the form of simple concepts.
So the description of the above process, you can call it "algorithm", this algorithm is specifically for the problem of "cooking instant noodles".
You will notice that there are many implied things in the above example:I said that you originally had a pack of instant noodles, but you also need pots, water, etc.
We may be in a specific situation where all these things are unavailable, and then we have to use another algorithm(perhaps to make the cauldron yourself).
In the above process, the instructions(steps) I used are relatively "precise", but we can streamline to fewer instructions, or expand to more instructions. You might say that if you want to be more precise, you have to explain how to put water in the pot.
If the person who wants to cook instant noodles according to this recipe does not know how to execute the command "pour the right amount of water in the pan", it is necessary to explain in simpler terms(for example, to explain how to use the tap).
Similarly, when we are programming, the accuracy of the algorithm you use depends on many parameters:the programming language you use, the libraries available, and so on.
4 . Computer "privileged" role
If we can find the traces of the algorithm in our daily lives, why do we discuss it mainly in Computer Science?
The reason is simple:computers(or computers) are very good at performing repetitive tasks. They are fast, efficient, and "lainous", never tired.
Suppose we can describe the algorithm for calculating the square root of 3(this algorithm must be operable by humans). Using this algorithm, you can use paper and pen to calculate the first 7 decimal places of the square root of 3(1.7320508).
But what if you need to calculate the first 100,000 decimal places of the square root of 3? Using paper and pen will count suspicious life. At this time, the computer will become more suitable.
We can design many algorithms for information processing. When it comes to information processing, there are usually the following categories:
- the study
Computers are usually more advantageous in these areas and can handle large amounts of information well.
You may have thought of Google, the famous search engine(Google initially relied on the strength of its search algorithm to dominate the market and achieve today's super high market value), but this activity is not limited to the Internet.
When you play Real-Time Strategy Game(RTS for short. For example, Red Alert, StarCraft, etc.), if you give a command to a unit, let it move. At this time, the computer needs to grasp a lot of information(such as the structure of the map, the start point of the unit, and the end point of the unit), and it must also generate new information:the route the unit should take.
So in fact, the algorithm comes from life(after all, the algorithm is conceived by people), but we usually discuss algorithms in the field of IT because of the particularity of computers.
5 . What is a data structure
The algorithm is mentioned above, now let's talk about the data structure. The English of data structure is Data Structure. data means "data" and structure means "structure".
In addition to processing information(data is the symbolic representation or carrier of information, information is the connotation of data), you must also consider how to store information. The way information is stored may have a very important effect on how it is processed.
Specifically, we can use a dictionary as an example. We can define a dictionary as "a collection of words and their definitions"(one word corresponds to one definition).
If the words in a dictionary are sorted randomly, such a dictionary should be difficult to use. For example, if you want to find the definition of a word, you have to turn the dictionary page by page until you find the word.
Arranging words alphabetically is obviously a very effective solution to find the word you want quickly. Therefore, this is a good way to store information.
There is a very close relationship between the algorithm(description method) and the data structure(description organization).
To put it simply, the storage method of information is the matter of data structure, and the processing method of information is the thing of algorithm.
Generally, certain data structures are essential for the implementation of certain algorithms; vice versa.
For example, if we want to add a new word to an already alphabetized dictionary, we ca n t just write this new word in a blank space on the last page of the dictionary, but we must add it to the correct one using an algorithm s position.
Therefore, the study of data structure and the study of algorithms are inseparable, we need to learn them at the same time.
6 . The first part of the second lesson
Today's class is here, come on!
In the next lesson, we will use a short story to lead to the learning of algorithmic complexity(the real algorithmic complexity will be discussed in Lesson 3):
My name is , the public number "[Programmer League]( https://github.com/frogoscar/ProgrammerLeague/blob/master/qrcode . "jpg)" operator, elite lecturer Ms. Oscar , a lifelong learner.
Love life, like swimming and have a little understanding of cooking.
Life motto:"Go straight to the benchmark"