- 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
1K+ Views
Printing all permutations of a given string is an example of backtracking problem. We will reduce the size of the substring to solve the sub-problems, then again backtrack to get another permutation from that section.For an example, if the string is ABC, the all permutations will be ABC, ACB, BAC, BCA, CAB, CBA.The complexity of this algorithm is O(n!). It is a huge complexity. When the string size increases, it takes a longer time to finish the task.Input and OutputInput: A string “ABC” Output: All permutations of ABC is: ABC ACB BAC BCA CBA CABAlgorithmstringPermutation(str, left, right)Input: The string and left ... Read More
610 Views
A list of different locks and another list of keys are given. Our task is to find the correct match of lock and key from the given list, and assign that key with the lock when it is correct.In this approach we will traverse all of the locks and create a hash-map, after that, each key is searched in the hash-map. When the key is matches, then that is marked as a valid key and assigned with a lock.Input and OutputInput: The lists of locks and keys. lock = { ), @, *, ^, (, %, !, $, &, #} ... Read More
1K+ Views
A list of different nuts and another list of bolts are given. Our task is to find the correct match of nuts and bolts from the given list, and assign that nut with the Bolt, when it is matched.This problem is solved by the quick-sort technique. By taking the last element of the bolt as a pivot, rearrange the nuts list and get the final position of the nut whose bolt is the pivot element. After partitioning the nuts list, we can partition the bolts list using the selected nut. The same tasks are performed for left and right sub-lists ... Read More
433 Views
Let us consider a string is given, we know that the string is a sequence of characters. The Lexicographical rotation is the rotation of string, to convert characters in lexicographical order.The solution is simple, we simply concatenate the given string with itself, then in another array, all rotation of strings are stored. After that sort the array in ascending order, the lowest value is the final result.Input and OutputInput: The String “BCAAFAABCD” Output: Rotated String: “AABCDBCAAF”AlgorithmminStrRotation(str)Input − The given string.Output − Minimum string rotation required.Begin n := length of str define strArr to store all rotations tempStr := ... Read More
793 Views
From a set of data, this algorithm will find the largest element to kth largest element of the array.This problem can be solved easily by sorting the array. We can sort them either in ascending order or in descending order. Solving it in descending order, we can get first k elements to find our result.Input and OutputInput: The elements of an array: {1, 23, 12, 9, 30, 2, 50, 63, 87, 12, 45, 21}, K = 4 Output: 4 largest elements are 87 63 50 45AlgorithmkthLargestElement(array, n, k)Input: The array, number of elements in the array, place k.Output: Display largest ... Read More
2K+ Views
Jarvis March algorithm is used to detect the corner points of a convex hull from a given set of data points.Starting from a leftmost point of the data set, we keep the points in the convex hull by anti-clockwise rotation. From a current point, we can choose the next point by checking the orientations of those points from the current point. When the angle is largest, the point is chosen. After completing all points, when the next point is the start point, stop the algorithm.Input and OutputInput: Set of points: {(-7, 8), (-4, 6), (2, 6), (6, 4), (8, 6), ... Read More
5K+ Views
The convex hull is the minimum closed area which can cover all given data points.Graham’s Scan algorithm will find the corner points of the convex hull. In this algorithm, at first, the lowest point is chosen. That point is the starting point of the convex hull. Remaining n-1 vertices are sorted based on the anti-clockwise direction from the start point. If two or more points are forming the same angle, then remove all points of the same angle except the farthest point from start.From the remaining points, push them into the stack. And remove items from stack one by one, ... Read More
947 Views
All even numbers from 4, can be expressed as a sum of two prime numbers. Sometimes a number can have more than one sum of the prime number combination.For an example the number 10 = (5 + 5) and (7 + 3)This algorithm will find all of the combinations of prime sums for a given number. When one number x is prime, then only we will check whether (number - x) is prime or not, if yes, the sum of x and (number – x) represents the even number.Input and OutputInput: Even number: 70 Output: Prime sums 70 = 3 ... Read More
1K+ Views
One matrix is given; the matrix is representing the one screen. Each element (i, j) of the screen is denoted as a pixel, the color of that pixel is marked with different numbers. In this algorithm, the pixels will be filled with new color when it is already in selected previous color. If the previous color is not the previous color, that pixel will not be filled. After filling a pixel, it will check for its up, down, left and right pixels to do the same.The idea is really simple, first, we check whether the selected position is colored with ... Read More
2K+ Views
This algorithm will convert a given number into English words. Like 564 will be Five Hundred and Sixty-Four. For this algorithm, some predefined strings are given, from that list, it will get the proper words to make into words.The lists are like Units: it will hold all words for (0 to 9) like Zero, One…Nine twoDigits: it will hold all numbers from (10 - 19), like Ten, eleven…NineteentenMul: For ten multiples, (20-90), like Twenty, Thirty, … Ninety.tenPower: It is for Hundred and Thousands as power 2 and 3 of 10Input and OutputInput: The number: 568 Output: Five Hundred And Sixty EightAlgorithmnumToWord(num)there are some ... Read More