Skip to content

Category Archives: Randomized

What is a Randomized Algorithm? An algorithm that uses random numbers to decide what to do next anywhere in its logic is called a Randomized… Read More
We have introduced and discussed below Karger’s algorithm in set 1. 1) Initialize contracted graph CG as copy of original graph 2) While there are… Read More
Given a singly linked list, select a random node from the linked list (the probability of picking a node should be 1/N if there are… Read More
Given an undirected and unweighted graph, find the smallest cut (smallest number of edges that disconnects the graph into two components). The input graph may have… Read More
Consider a high traffic website that receives millions of requests (of different types) per five minutes, the site has k (for example n = 1000)… Read More
Consider the following famous puzzle. In a country, all families want a boy. They keep having babies till a boy is born. What is the expected… Read More
Prerequisite: Random Variable This post is about mathematical concepts like expectation, linearity of expectation. It covers one of the required topics to understand Randomized Algorithms.… Read More
How many people must be there in a room to make the probability 100% that at-least two people in the room have same birthday? Answer: 367… Read More
We recommend reading the following post as a prerequisite of this post. K’th Smallest/Largest Element in Unsorted Array | Set 1 Given an array and… Read More
You are given a function rand(a, b) which generates equiprobable random numbers between [a, b] inclusive. Generate 3 numbers x, y, z with probability P(x),… Read More
Given n numbers, each with some frequency of occurrence. Return a random number with probability proportional to its frequency of occurrence. Example:  Let following be… Read More
Given a stream of numbers, generate a random number from the stream. You are allowed to use only O(1) space and the input is in… Read More
Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items, where n is either a very… Read More
Given an array, write a program to generate a random permutation of array elements. This question is also asked as “shuffle a deck of cards”… Read More
You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40%… Read More

Start Your Coding Journey Now!