# Why Discrete Maths?

Published Feb 17, 2017Last updated Mar 06, 2017

This is a question a lot of people have asked over and over again. There are also a lot of articles that have done justice to answering this question on the Internet. The purpose of this post is to summarise the common answers I found on the internet.

Discrete Maths, unlike other branches of mathematics, helps to develop a logical approach to problem solving, which, hopefully you agree, is a very important skill that all programmers need to have. Of course, you will most likely never open your Discrete Maths textbook and copy something into your code to solve a problem. However, understanding the concepts will help developers write better code, better algorithms, and use design patterns more effectively.

Not having a good knowledge of Discrete Maths limits you as a developer. Let me explain — if you are mainly focused on building web applications that implement basic CRUD operations or the most simple apps, then you probably don't need to understand Discrete Maths. However, if you wanted to challenge yourself as a developer by building more complex projects — a search engine or an aggregation tool, a graphics software, an AI project, etc. — then a good knowledge of Discrete Maths would be very useful.

The most useful and interesting part of Discrete Maths for me is probability and combinatorics because I could relate to their use in solving real life problems.

Example of how discrete maths can be applied to real life problems

Say, I wanted to build an app that advises users on the best bets to place. Specifically, let’s take this scenario: Brian has the option of placing a bet on a certain basketballer (Kevin Curry) making his third free throws of his fifth attempt or him making exactly 4 throws out of five throws. He needs to know the best option to go for. Kevin is an above-average free-throw taker who makes 63% of his throws.

Here’s how I would solve the problem using Discrete Maths

Solution:

For him to score his 3rd free throw in his fifth attempt, he has to make 2 throws out of his first four attempts:

  so we have P(2 in 4 attempts) * P(success in the 5th attempt)


To get the probability that he has 2 in 4 attempts, I will use combination to get the possible outcomes and then multiply with the probability of making two shots and the probability of missing 2 shots:

  4C2 = 4!/2!(4–2)! = 6 possible outcomes

If Kevin has 63% chance of making a throw then he has 37% (100-63) of missing a throw

P(of making a throw) = 63/100 = 0.63
P(of not making a throw) = 1 - 0.63 = 0.37

To make 2 throws out of four throws, it means Kevin has to make 2 throws and 	miss the other two throws. Considering this,
P(Kevin making exactly two out of four throws) = Possible outcomes * P(making throws twice) * P(missing throws twice).
Let's rewrite it as
P(2/4) = 6 * 0.63^2 * 0.37^2 = 0.326

P(making 3rd throw in fifth attempt) = P(making exactly 2 throws of 4 attempts) * P(making a throw in fifth attempt).
Let's rewrite it as
P(3/5) = P(2/4)* P(making the 5th throw)
= 0.326 * 0.63
= 0.2054


So the probability of him making his 3rd throw in his fifth attempt = 20.54%

Now let’s find the probability of him making 4 of the 5 throws:

For Kevin to make exactly 4 of five throws, it means he has to miss one throw and make four throws so,

P(Kevin making exactly four out of five throws) = Possible outcomes of making 4 of 5 throws * P(making throws four times) * P(missing one throw).

P(4/5) = 5C4 = 5!/4!(5–4)! * 0.63 ^ 4 * 0.37 ^ 1

= 5 * 0.1575 * 0.37

= 0.2914


The probability of Kevin making 4 of his 5 throws is 29.14%

So we can see that the probability of Kevin making his 3rd throw in his 5th attempt is lower than the probability of him making exactly 4 of 5 throws. Therefore, the best option for Brian is to place his bet on Kevin making 4 of the 5 throws.

The knowledge of discrete maths helps you write a good algorithm for your app’s recommendation logic.

There are also several other real-world problems that discrete maths help to solve e.g building a scheduling application, building games.

This post was originally posted by the author here. This version has been edited for clarity and may appear different from the original post.