Found 1862 Articles for Data Structure

Aho-Corasick Algorithm

Sharon Christine
Updated on 15-Jun-2020 16:35:18

1K+ Views

This algorithm is helpful to find all occurrences of all given set of keywords. It is a kind of Dictionary-matching algorithm. It uses a tree structure using all keywords. After making the tree, it tries to convert the tree as an automaton to make the searching in linear time. There are three different phases of Aho-Corasick Algorithm. These are Go-to, Failure, and Output. In the go-to stage, it makes the tree using all the keywords. In the next phase or in the Failure Phase, it tries to find the backward transition to get a proper suffix of some keywords. In the ... Read More

Prim’s MST for Adjacency List Representation

Sharon Christine
Updated on 15-Jun-2020 17:13:06

2K+ Views

It is similar to the previous algorithm. Here the only difference is, the Graph G(V, E) is represented by an adjacency list.Time complexity adjacency list representation is O(E log V).Input and OutputInput: The cost matrix: Output: Edge: A--B And Cost: 1 Edge: B--E And Cost: 2 Edge: A--C And Cost: 3 Edge: A--D And Cost: 4 Edge: E--F And Cost: 2 Edge: F--G And Cost: 3 Total Cost: 15Algorithmprims(g: Graph, start)Input −  The graph g and the seed vertex named ‘start’Output − The Tree after adding edges.Begin    create two set B, N    add the start node in B ... Read More

Prim’s Minimum Spanning Tree Algorithm

karthikeya Boyini
Updated on 15-Jun-2020 17:22:04

2K+ Views

There is a connected graph G(V, E) and the weight or cost for every edge is given. Prim’s Algorithm will find the minimum spanning tree from the graph G. It is a growing tree approach. This algorithm needs a seed value to start the tree. The seed vertex is grown to form the whole tree.The problem will be solved using two sets. One set holds the nodes that are already selected, and another set holds the item those are not considered yet. From the seed vertex, it takes adjacent vertices, based on minimum edge cost, thus it grows the tree by ... Read More

Minimum Number of Platforms Problem

Sharon Christine
Updated on 15-Jun-2020 15:48:57

505 Views

A list of arrival and departure time is given. Now the problem is to find the minimum number of platforms are required for the railway as no train waits.By sorting all timings in sorted order, we can find the solution easily, it will be easy to track when the train has arrived but not left the station.The time complexity of this problem is O(n Log n).Input and OutputInput: Lists of arrival time and departure time. Arrival: {900, 940, 950, 1100, 1500, 1800} Departure: {910, 1200, 1120, 1130, 1900, 2000} Output: Minimum Number of Platforms Required: 3AlgorithmminPlatform(arrival, departure, int n)Input − The ... Read More

Minimum Coin Change Problem

karthikeya Boyini
Updated on 15-Jun-2020 15:51:47

997 Views

There is a list of coin C(c1, c2, ……Cn) is given and a value V is also given. Now the problem is to use the minimum number of coins to make the chance V.Note − Assume there are an infinite number of coins CIn this problem, we will consider a set of different coins C{1, 2, 5, 10} are given, There is an infinite number of coins of each type. To make change the requested value we will try to take the minimum number of coins of any type.As an example, for value 22 − we will choose {10, 10, 2}, ... Read More

Efficient Huffman Coding for Sorted Input

Sharon Christine
Updated on 15-Jun-2020 16:08:20

455 Views

In the previous Huffman code problem, the frequency was not sorted. If the frequency list is given in sorted order, the task of assigning code is being more efficient.In this problem, we will use two empty queues. Then create a leaf node for each unique character and insert it into the queue in increasing order of frequency.In this approach, the complexity of the algorithm is O(n).Input and OutputInput: Different letters and their frequency in sorted order Letters: {L, K, X, C, E, B, A, F} Frequency: {1, 1, 2, 2, 2, 2, 3, 4} Output: Codes for the letters L: ... Read More

Huffman Coding Algorithm

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

32K+ 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 Algorithm for Adjacency List Representation

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

5K+ 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

4K+ 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

Pigeonhole Sort

Sharon Christine
Updated on 15-Jun-2020 15:31:17

760 Views

This is an example of the non-comparison sorting technique. It is used where the number of items and the range of possible key values is approximately the same.To perform this sort, we need to make some holes. The number of holes needed is decided by the range of numbers. In each hole, items are inserted. Finally deleted from the hole and stored into an array for sorted order.The complexity of Pigeon-Hole Sort TechniqueTime Complexity: O(n+2^k)Space Complexity: O(2^k)Input and OutputInput: The unsorted list: 802 630 20 745 52 300 612 932 78 187 Output: Data before Sorting: 802 630 20 745 ... Read More

Advertisements