Found 14 Articles for Greedy Algorithm

Huffman Coding Algorithm

karthikeya Boyini
Updated on 23-Dec-2022 11:05:46

31K+ Views

Huffman coding is a lossless data compression algorithm. In this algorithm, a variable-length code is assigned to input different characters. The code length is related to how frequently characters are used. Most frequent characters have the smallest codes and longer codes for least frequent characters.There are mainly two parts. First one to create a Huffman tree, and another one to traverse the tree to find codes.For an example, consider some strings “YYYZXXYYX”, the frequency of character Y is larger than X and the character Z has the least frequency. So the length of the code for Y is smaller than ... Read More

Dijkstra’s Shortest Path Algorithm

Samual Sam
Updated on 15-Jun-2020 16:17:25

2K+ Views

The main problem is the same as the previous one, from the starting node to any other node, find the smallest distances. In this problem, the main difference is that the graph is represented using the adjacency matrix. (Cost matrix and adjacency matrix is similar for this purpose).For the adjacency list representation, the time complexity is O(V^2) where V is the number of nodes in the graph G(V, E)Input and OutputInput: The adjacency matrix: Output: 0 to 1, Using: 0, Cost: 3 0 to 2, Using: 1, Cost: 5 0 to 3, Using: 1, Cost: 4 0 to 4, ... Read More

Dijkstra’s Algorithm for Adjacency List Representation

karthikeya Boyini
Updated on 15-Jun-2020 16:25:50

4K+ Views

There is a given graph G(V, E) with its adjacency list representation, and a source vertex is also provided. Dijkstra’s algorithm to find the minimum shortest path between source vertex to any other vertex of the graph G.To Solve this problem, we will use two lists. One is to store vertices which have been considered as the shortest path tree, and another will hold the vertices which are not considered yet. In each phase of the algorithm, we find the unconsidered vertex and which has the minimum distance from the source.Another list is used to hold the predecessor node. Using ... Read More

Activity Selection Problem

Samual Sam
Updated on 15-Jun-2020 16:28:54

3K+ Views

There are n different activities are given with their starting time and ending time. Select the maximum number of activities to solve by a single person. We will use the greedy approach to find the next activity whose finish time is minimum among rest activities, and the start time is more than or equal with the finish time of the last selected activity.The complexity of this problem is O(n log n) when the list is not sorted.When the sorted list is provided the complexity will be O(n).Input and OutputInput: A list of different activities with starting and ending times. {(5, ... Read More

Advertisements