Found 510 Articles for Algorithms

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

Cycle Sort

Sharon Christine
Updated on 15-Jun-2020 15:43:42

627 Views

Cycle Sort is an in-place sorting algorithm. It is also a comparison based sort and efficient for any other in-place sorting technique. It finds the minimum number of memory write to perform the sorting tasks.The complexity of Cycle Sort TechniqueTime Complexity: O(n^2)Space Complexity: O(1)Input and OutputInput: A list of unsorted data: 23 63 98 74 20 14 36 45 99 78 Output: Array before Sorting: 23 63 98 74 20 14 36 45 99 78 Array after Sorting: 14 20 23 36 45 63 74 78 98 99AlgorithmcycleSort(array, size)Input − An array of data, and the total number in the ... Read More

Comb Sort

Jai Janardhan
Updated on 15-Jun-2020 14:29:38

994 Views

The basic idea of comb sort and the bubble sort is same. In other words, comb sort is an improvement on the bubble sort. In the bubble sorting technique, the items are compared with the next item in each phase. But for the comb sort, the items are sorted in a specific gap. After completing each phase, the gap is decreased. The decreasing factor or the shrink factor for this sort is 1.3. It means that after completing each phase the gap is divided by 1.3.The complexity of Comb Sort TechniqueTime Complexity: O(n log n) for the best case. O(n^2/2^p) (p ... Read More

Ternary Search

Rishi Raj
Updated on 15-Jun-2020 14:50:10

3K+ Views

Like the binary search, it also separates the lists into sub-lists. This procedure divides the list into three parts using two intermediate mid values. As the lists are divided into more subdivisions, so it reduces the time to search a key value.The complexity of Ternary Search TechniqueTime Complexity: O(log3 n)Space Complexity: O(1)Input and OutputInput: A sorted list of data: 12 25 48 52 67 79 88 93 The search key 52 Output: Item found at location: 3AlgorithmternarySearch(array, start, end, key)Input − An sorted array, start and end location, and the search keyOutput − location of the key (if found), otherwise wrong ... Read More

Exponential Search

Paul Richard
Updated on 15-Jun-2020 14:10:42

4K+ Views

Exponential search is also known as doubling or galloping search. This mechanism is used to find the range where the search key may present. If L and U are the upper and lower bound of the list, then L and U both are the power of 2. For the last section, the U is the last position of the list. For that reason, it is known as exponential.After finding the specific range, it uses the binary search technique to find the exact location of the search key.The complexity of Exponential Search TechniqueTime Complexity: O(1) for the best case. O(log2 i) ... Read More

Operating system time slicing in round robin scheduling

Arnab Chakraborty
Updated on 20-Jun-2020 09:50:34

202 Views

process Burst time A 4 B 1 C 8 D 1time slice=10 unitA B C D A C C C 0 2 3 5 6 8 10 12 14So A will complete 8 cycles.

Advertisements