Skip to content

Category Archives: Greedy

We recommend reading the following two posts as a prerequisite of this post.1. Greedy Algorithms | Set 7 (Dijkstra’s shortest path algorithm) 2. Graph and its representationsWe… Read More
  Given a graph and a source vertex in the graph, find shortest paths from source to all vertices in the given graph.Dijkstra’s algorithm is… Read More
We recommend to read following two posts as a prerequisite of this post. 1. Greedy Algorithms | Set 5 (Prim’s Minimum Spanning Tree (MST)) 2.… Read More
  We have discussed Kruskal’s algorithm for Minimum Spanning Tree. Like Kruskal’s algorithm, Prim’s algorithm is also a Greedy algorithm. It starts with an empty spanning tree.… Read More
We recommend to read following post as a prerequisite for this.Greedy Algorithms | Set 3 (Huffman Coding)Time complexity of the algorithm discussed in above post… Read More
Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based… Read More
What is Minimum Spanning Tree? Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects… Read More
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can… Read More
  Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and… Read More
  Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = {… Read More
Following two algorithms are generally taught for Minimum Spanning Tree (MST) problem. Prim’s algorithm Kruskal’s algorithm There is a third algorithm called Boruvka’s algorithm for… Read More
Minimum Spanning Tree (MST) problem: Given connected graph G with positive edge weights, find a min weight set of edges that connects all of the… Read More
  Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.   Rotation of the above array by 2 will make… Read More
A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with… Read More