Many of you when you first start learning programming often ask the question: Does learning programming need to be good at MATH?.
In general, to learn programming, we don’t need to be too good at Math, but you also have to know at a basic level, this problem CTV Le Dinh Hoang Vu It was made very clear in the previous post.
But if you are good at Math, it will certainly save you a lot of time and effort when you start “coding”.
To understand specifically the role of Mathematics in the programming profession, first, we need to understand what programming is?
#first. What is programming?
Life is full of problems that need to be solved. And to solve it, we can do it “manually” by hand or by machine.
However, there are repetitive jobs, or jobs that need to be calculated on a large scale, if done manually, it will be very resource-intensive, time-consuming and generally “useless”.
Then, programming will help us solve that problem more effectively, saving time and effort.
So to understand it roughly: Programming is the practice of instructing a computer to perform various tasks and jobs in a language it understands.
The language that the computer understands is called . programming language.
In order for the computer to do the job correctly, we must come up with a correct way of doing it, including clear steps, which is called algorithm. So to program we need two things, which are: Programming languages and algorithms.
#2. Programming language
There are many popular programming languages these days and it is not difficult to get access to these languages through documents, books or even courses on Youtube.
Learning a programming language also depends on the purpose of programming. You can refer to the number of people using languages through the following table:
In general, learning a programming language does not depend much on whether you are good at Math or not.
However, as I said at the beginning of her writing, you should also know the basics of Math so that while approaching a new programming language, you can practice the “code” of that language through lessons such as: Finding numbers maximum, sum of arrays, etc.
Next, we come to the most important part of this article, which is algorithms and the application of Mathematics to algorithm research.
#3. What is the benefit of being good at Math when making an algorithm?
With that said, an algorithm is a step-by-step process to solve a particular problem. A problem can have many ways to solve, similarly, a problem can have many algorithms to solve. Roughly speaking like this:
Consider the simple problem of finding a way from home A come home EASY With the map as shown below, we see there are two ways to handle this problem.
- Option 1: House A Old house EASY house
- Option 2: House A BO’s house EASY house E .’s house EASY house
Obviously, if we put the problem in practice, then Way 1 It will save time, effort and save a lot of gas money.
Similarly, in programming we also have many algorithms to solve a problem, but people always want to find the best algorithm to solve the problem, in order to save time. time.
A problem solved with the right algorithm can only take a few seconds to produce a result. Meanwhile, the same problem, but with a bad algorithm, it can take up to a few minutes to perform.
=> Then being good at Math plays a very important role in finding the optimal algorithm.
There are two reasons:
- Firstly, people who are good at Math are often very good at logical thinking, so the algorithms they find are also “better” than those who are not good at math.
- Second, people who are good at Math will handle problems in an academic way rather than trying thousands of tests.
I will illustrate specifically for you through some of the following problems: (I will use Python language – a very popular language today).
#4. The problem of calculating the sum of regular numbers
Sum of word numbers 1
arrive n
and print to the screen.
For this problem, the simplest way is to use loop for
(or conditional loop while
) like the following code:
However, if you are good at Math, you will immediately know the formula:
Then, you can “code” two lines to get the following result:
Another example is the problem Sum of squares from 1 to: If we do it in a simple way using a for loop, we have the following code:
However, if you know the formula, we have a shorter code like this:
#5. Math problems with large numbers
Problem: Input from the keyboard positive integer n
tell me how many of the numbers end in 0
.
If you are not good at Math, you can do it manually by running a loop for
and of course the code will be long and the result will run longer like this:
But if you’re good at Math, it won’t be hard for you to spot:
And from above, since the product always contains 2.5, it always ends with 0. So the result of the above problem is (if n > 4)
You can see that if you enter from the keyboard a very large number, such as n = 10000, the first way the machine will run for a long time, but the second way, the results will be almost instantaneous.
#6. summary
Well, then obviously being good at Math will have a lot of advantages in programming right?! Being good at Math not only produces faster results, but the length of the code is also shorter and more optimized.
I just took two simple examples so that you can easily imagine, in reality there are many more complex problems like that.
If you are not good at Math, you can still program, but the algorithm you give can be very complicated in some cases where people who are good at Math can come up with a much more concise algorithm.
Some simple math problems like in #5, if you do it manually, the results may take a long time (with a very large number of keyboard inputs), but if you have a little thought, the results will come out. almost immediate results.
In short, people who are not good at Math can still program, but will lose more than those who are good at Math. So to be effective when coding, you should develop more in Math.
CTV: Vo Thinh Phat – Blogchiasekienthuc.com
Edit by Kien Nguyen
Note: Was this article helpful to you? Don’t forget to rate the article, like and share it with your friends and family!