Category Archives: Greedy

Maximize the sum of arr[i]*iOctober 15, 2017

Given an array of N integers. You are allowed to rearrange the element of the array. The task is to find the maximum value of… Read More »

Lexicographically largest subsequence such that every character occurs at least k timesOctober 14, 2017

Given a string S and an integer K. The task is to find lexicographically largest subsequence of S, say T, such that every character in… Read More »

Policemen catch thievesOctober 9, 2017

Given an array of size n that has the following specifications: Each element in the array contains either a policeman or a thief. Each policeman… Read More »

Minimum rotations to unlock a circular lockOctober 8, 2017

You are given a lock which is made up of n-different circular rings and each ring has 0-9 digit printed serially on it. Initially all… Read More »

Correctness of Greedy AlgorithmsOctober 4, 2017

A greedy algorithm selects a candidate greedily (local optimum) and adds it to the current solution provided that it doesn’t corrupt the feasibility. If the… Read More »

Job Scheduling with two jobs allowed at a timeSeptember 24, 2017

We are given N jobs, and their starting and ending times. We can do two jobs simultaneously at a particular moment. If one job ends… Read More »

Buy Maximum Stocks if i stocks can be bought on i-th day

In a stock market, there is a product with its infinite stocks. The stock prices are given for N days, where arr[i] denotes the price… Read More »

Program for Next Fit algorithm in Memory ManagementSeptember 13, 2017

Prerequisite: Partition allocation methods What is Next Fit ? Next fit is a modified version of ‘first fit’. It begins as first fit to find… Read More »

Scheduling priority tasks in limited time and minimizing lossSeptember 12, 2017

Given n tasks with arrival time, priority and number of time units they need. We need to schedule these tasks on a single resource. The… Read More »

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 »