Category Archives: Algorithm

Recursion

What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. Using recursive algorithm, certain problems can be solved quite easily. Examples of such problems are Towers of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc. What is base… Read More »

Find two prime numbers with given sum

Given an even number (greater than 2 ), print two prime numbers whose sum will be equal to given number. There may be several combinations possible. Print only first such pair. An interesting point is, a solution always exist according to Goldbach’s conjecture. Examples: Input: n = 74 Output: 3 71 Input : n =… Read More »

Count of parallelograms in a plane

Given some points on a plane, which are distinct and no three of them lie on the same line. We need to find number of Parallelograms with the vertices as the given points. Examples: Input : points[] = {(0, 0), (0, 2), (2, 2), (4, 2), (1, 4), (3, 4)} Output : 2 Two Parallelograms… Read More »

Print all palindromic partitions of a string

Given a string s, partition s such that every string of the partition is a palindrome. Return all possible palindrome partitioning of s. Example : Input : s = “bcc” Output : [[“b”, “c”, “c”], [“b”, “cc”]] Input : s = “geeks” Output : [[“g”, “e”, “e”, “k”, “s”], [“g”, “ee”, “k”, “s”]] We have… Read More »