Found 1900 Articles for Data Structure

Minimum Coin Change Problem

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

942 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

Kruskal’s Minimum Spanning Tree Algorithm

Sharon Christine
Updated on 15-Jun-2020 16:00:50

4K+ Views

There is a connected graph G(V, E) and the weight or cost for every edge is given. Kruskal’s algorithm will find the minimum spanning tree using the graph and the cost.It is the merge-tree approach. Initially, there are different trees, this algorithm will merge them by taking those edges whose cost is minimum, and form a single tree.In this problem, all of the edges are listed and sorted based on their cost. From the list, edges with minimum costs are taken out and added in the tree, and every there is a check whether the edge forming cycle or not, ... Read More

Job Sequencing Problem with Deadlines

karthikeya Boyini
Updated on 15-Jun-2020 16:04:43

2K+ Views

In this problem, there is a list of jobs given. In the list, the deadline and the profits are also given for each job. Every job will take a single unit of time, so the minimum deadline for a job is 1. If only one job can be scheduled at a time, then maximize the profit.To solve this problem, all subset of the set of jobs are generated to check whether the individual subset is feasible or not. Also, keep track on maximum profit for all feasible subset that has generated.The time complexity of this algorithm is O(n^2)Input and OutputInput: ... Read More

Efficient Huffman Coding for Sorted Input

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

431 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

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

Shell Sort

karthikeya Boyini
Updated on 15-Jun-2020 14:58:31

639 Views

The shell sorting technique is based on the insertion sort. In the insertion sort sometimes we need to shift large block to insert an item in the correct location. Using shell sort, we can avoid a large number of shifting. The sorting is done with a specific interval. After each pass, the interval is reduced to make the smaller interval.The complexity of the Shell Sort TechniqueTime Complexity: O(n log n) for best case, and for other cases, it depends on the gap sequence.Space Complexity: O(1)Input and OutputInput: The unsorted list: 23 56 97 21 35 689 854 12 47 66 ... Read More

Selection Sort

Samual Sam
Updated on 15-Jun-2020 15:02:02

2K+ Views

In the selection sort technique, the list is divided into two parts. In one part all elements are sorted and in another part the items are unsorted. At first, we take the maximum or minimum data from the array. After getting the data (say minimum) we place it at the beginning of the list by replacing the data of first place with the minimum data. After performing the array is getting smaller. Thus this sorting technique is done.The complexity of Selection Sort TechniqueTime Complexity: O(n^2)Space Complexity: O(1)Input and OutputInput: The unsorted list: 5 9 7 23 78 20 Output: Array ... Read More

Advertisements