- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 546 Articles for Algorithms
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
427 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
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
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
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
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
637 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
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
2K+ Views
Radix sort is a non-comparative sorting algorithm. This sorting algorithm works on the integer keys by grouping digits which share the same position and value. The radix is the base of a number system. As we know that in the decimal system the radix or base is 10. So for sorting some decimal numbers, we need 10 positional boxes to store numbers.The complexity of Radix Sort TechniqueTime Complexity: O(nk)Space Complexity: O(n+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 52 300 612 932 78 187 ... Read More
3K+ Views
The quicksort technique is done by separating the list into two parts. Initially, a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than the pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using the same procedure.The complexity of Quicksort TechniqueTime Complexity: O(n log n) for best case and average case, O(n^2) for the worst case.Space Complexity: O(log n)Input and OutputInput: The unsorted list: 90 45 22 11 22 50 Output: Array before Sorting: 90 45 22 11 22 50 Array after Sorting: 11 22 ... Read More
To Continue Learning Please Login
Login with Google