Probability in Computer Science (original) (raw)

Last Updated : 22 Jul, 2025

Probability is the science of uncertainty —and in computer science, uncertainty is everywhere. Whether it’s predicting what movie you’ll watch next, how secure your password is, or how long an algorithm might take to run, probability plays a key role. It helps computers make smart guesses, deal with randomness, and perform better in the real world.

It plays a crucial role in numerous fields, providing a framework for making informed decisions in uncertain situations.

probability-for-computer-science

Appliaction of probability for Computer Science

**Uses of Probability in Computer Science

There are various applications of probability in real life that include:

Through these applications, probability theory demonstrates its versatility and importance in navigating uncertainty and optimizing outcomes in various professional and everyday contexts.

Probability Concepts in Computer Science

Conditional Probability and Bayes' Theorem

**Conditional Probability is the probability of an event **A occurring, **given that another event **B has already occurred. Given by:

P(A∣B) =\frac{ P(A∩B)}{P(B)}

Bayes' Theorem states that given P(B)>0, the probability of A given B is denoted by:

P(A∣B) =\frac{ P(B∣A) ×P(A)}{P(B)}

**Application of Conditional Probability and Theorem in CS

The **Naive Bayes Classifier is a **probability-based machine learning algorithm used for **classification tasks. It applies **Bayes’ Theorem to predict the class of a data point, assuming that all features are **independent of each other (this is the "naive" assumption).
Compute the prior probability of each class. -> Compute the likelihood of each events -> Using Bayes Theorem estimate posterior probability(**updated probability of an event) -> Selecting the class with the highest probability

Random Variables

A **random variable is a function that assigns a **numerical value to each **outcome in the sample space of a random experiment. This helps us to quantify randomness mathematically.

For a random variable x, PDF, PMF, and CDF.

Application of Random Variables in CS

Expectation and Variance

**Expectation (also called expected value) is the average or mean value you would expect from a random experiment if you repeat it many times.

**Variance measures how much the values of a random variable spread out from its average.

Application of Expectation and Variance in Probability