Category Archives: Greedy

Minimum Swaps for Bracket BalancingJuly 16, 2017

You are given a string of 2N characters consisting of N ‘[‘ brackets and N ‘]’ brackets. A string is considered balanced if it can… Read More »

Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)July 8, 2017

In previous post, we have discussed Set 1 of SJF i.e. non-preemptive. In this post we will discuss the preemptive version of SJF known as… Read More »

Fitting Shelves ProblemJune 25, 2017

Given length of wall w and shelves of two lengths m and n, find the number of each type of shelf to be used and… Read More »

Program for Page Replacement Algorithms | Set 2 (FIFO)June 17, 2017

Prerequisite : Page Replacement Algorithms In operating systems that use paging for memory management, page replacement algorithm are needed to decide which page needed to… Read More »

Program for Page Replacement Algorithms | Set 1 ( LRU)June 16, 2017

Prerequisite: Page Replacement Algorithms In operating systems that use paging for memory management, page replacement algorithm are needed to decide which page needed to be… Read More »

Huffman DecodingJune 15, 2017

We have discussed Huffman Encoding in a previous post. In this post decoding is discussed. Examples: Input Data : AAAAAABCCCCCCDDEEEEE Frequencies : A: 6, B:… Read More »

Find the minimum and maximum amount to buy all N candiesJune 12, 2017

In a candy store there are N different types of candies available and the prices of all the N different types of candies are provided.… Read More »

Assign Mice to Holes

There are N Mice and N holes are placed in a straight line. Each hole can accommodate only 1 mouse. A mouse can stay at… Read More »

Top 20 Greedy Algorithms Interview QuestionsApril 25, 2017

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate… Read More »

Minimum cost for acquiring all coins with k extra coins allowed with every coinApril 24, 2017

You are given a list of N coins of different denominations. you can pay an amount equivalent to any 1 coin and can acquire that… Read More »

Find maximum height pyramid from the given array of objectsApril 22, 2017

Given n objects, with each object has width wi. We need to arrange them in a pyramidal way such that : Total width of ith… Read More »

Minimum sum of absolute difference of pairs of two arraysApril 1, 2017

Given two arrays a[] and b[] of equal length n. The task is to pair each element of array a to an element in array… Read More »

Rearrange characters in a string such that no two adjacent are sameMarch 13, 2017

Given a string with repeated characters, task is rearrange characters in a string so that no two adjacent characters are same. Note : It may… Read More »

Maximize sum of consecutive differences in a circular arrayMarch 12, 2017

Given an array of n elements. Consider array as circular array i.e element after an is a1. The task is to find maximum sum of… Read More »

Program for Worst Fit algorithm in Memory ManagementMarch 6, 2017

Prerequisite : Partition allocation methods Worst Fit allocates a process to the partition which is largest sufficient among the freely available partitions available in the… Read More »