Mathematics and Programming

Muhammad Rizwan
3 min readJan 8, 2023

--

Math and programming are two subjects that may seem unrelated at first glance, but they are actually closely connected. In fact, math is a fundamental part of programming and is used in a variety of ways.

One of the most obvious ways math is used in programming is in the creation of algorithms. Algorithms are sets of instructions that a computer can follow to solve a problem or perform a task. These instructions often involve performing mathematical calculations, such as finding the average of a set of numbers or calculating the area of a circle.

For example, consider a simple algorithm written in the Python programming language that calculates the average of a set of numbers:

This algorithm takes a list of numbers as input and uses a loop to add up the values. The average is then calculated by dividing the sum by the total number of numbers. This process requires a basic understanding of arithmetic, including addition and division.

Math is also used in programming to represent and manipulate data. For example, in a computer graphics program, coordinates on a graph may be represented using mathematical equations. For example, the equation for a line in the form y = mx + b can be used to plot points on a graph. Similarly, 3D models in video games and other applications are often created using math to define their shape and position in space.

In addition to these practical uses, math concepts also provide the foundation for many programming languages and techniques. For example, the concept of a “variable” in programming, which refers to a piece of data that can change, is based on the mathematical concept of a variable. Similarly, programming languages often use symbols and notation similar to those found in math, such as the plus sign (+) for addition and the asterisk (*) for multiplication.

One specific example of math being used in programming is the concept of “Big O” notation. This notation is used to describe the efficiency of algorithms, and it is based on the idea of “order of growth.” For example, an algorithm with a time complexity of O(n) is said to have “linear” order of growth, because the running time of the algorithm increases linearly with the size of the input. An algorithm with a time complexity of O(n²) is said to have “quadratic” order of growth, because the running time increases with the square of the size of the input. Understanding these concepts requires a basic understanding of math, including the concept of exponents.

Overall, math and programming are interconnected subjects that are essential for anyone looking to pursue a career in computer science or a related field. Understanding math is not only important for writing efficient and effective code, but it is also necessary for understanding the underlying principles and concepts that form the foundation of computer science.

--

--

Muhammad Rizwan

Hello with islamic greetings As-Salam-u-Alaikum, I'm Muhammad Rizwan a freelance Games & Software developer based in Lahore.