Category Archives: Randomized

Random Walk (Implementation in Python)

Introduction A random walk is a mathematical object, known as a stochastic or random process, that describes a path that consists of a succession of… Read More »

Expectation or expected value of an array

Expectation or expected value of any group of numbers in probability is the long-run average value of repetitions of the experiment it represents. For example,… Read More »

Estimating the value of Pi using Monte Carlo

Monte Carlo estimation Monte Carlo methods are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. One of… Read More »

Binomial Random Variables

In this post, we’ll discuss Binomial Random Variables. Prerequisite : Random Variables A specific type of discrete random variable that counts how often a particular… Read More »

Randomized Binary Search Algorithm

We are given a sorted array A[] of n elements. We need to find if x is present in A or not.In binary search we… Read More »

Shuffle a deck of cards

Given a a of cards, task is to shuffle them. Asked in Amazon Interview Recommended: Please try your approach on {IDE} first, before moving on… Read More »

Program to generate CAPTCHA and verify user

A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a test to determine whether the user is human or not.… Read More »

Find an index of maximum occurring element with equal probability

Given an array of integers, find the most occurring element of the array and return any one of its indexes randomly with equal probability. Examples:… Read More »

Implement rand12() using rand6() in one line

Given a function rand6() that returns random numbers from 1 to 6 with equal probability, implement one-liner function rand12() using rand6() that returns random numbers… Read More »

Implement rand3() using rand2()

Given a function rand2() that returns 0 or 1 with equal probability, implement rand3() using rand2() that returns 0, 1 or 2 with equal probability.… Read More »

Generate 0 and 1 with 25% and 75% probability

Given a function rand50() that returns 0 or 1 with equal probability, write a function that returns 1 with 75% probability and 0 with 25%… Read More »

Randomized Algorithms | Set 0 (Mathematical Background)

Conditional Probability Conditional probability P(A | B) indicates the probability of even ‘A’ happening given that the even B happened.

Randomized Algorithms | Set 3 (1/2 Approximate Median)

We strongly recommend to refer below articles as a prerequisite of this. Randomized Algorithms | Set 1 (Introduction and Analysis) Randomized Algorithms | Set 2… Read More »

Primality Test | Set 2 (Fermat Method)

Given a number n, check if it is prime or not. We have introduced and discussed School method for primality testing in Set 1. Primality… Read More »

Randomized Algorithms | Set 2 (Classification and Applications)

We strongly recommend to refer below post as a prerequisite of this. Randomized Algorithms | Set 1 (Introduction and Analysis) Classification Randomized algorithms are classified… Read More »