We recommend to read following post as a prerequisite for this. Greedy Algorithms | Set 3 (Huffman Coding) Time complexity of the algorithm discussed in… Read More »
Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based… Read More »
Pascal’s triangle is a triangular array of the binomial coefficients. Write a function that takes an integer value n as input and prints first n… Read More »
What is Minimum Spanning Tree? Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and… Read More »
We know the Pascal’s Identity very well, i.e. ncr = n-1cr + n-1cr-1
Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items,
Write a function that takes two parameters n and k and returns the value of Binomial Coefficient C(n, k).
Given a string, find the longest substring which is palindrome. For example, if the given string is “forgeeksskeegfor”, the output should be “geeksskeeg”.
Following is a typical recursive implementation of Quick Sort that uses last element as pivot.
Given an array, write a program to generate a random permutation of array elements. This question is also asked as “shuffle a deck of cards”… Read More »
Given a string, print all permutations of it in sorted order. For example, if the input string is “ABC”, then output should be “ABC, ACB,… Read More »
Given a string, find its rank among all its permutations sorted lexicographically. For example, rank of “abc” is 1, rank of “acb” is 2, and… Read More »
Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once. Expected time complexity… Read More »
Given a number, check if it is divisible by 7. You are not allowed to use modulo operator, floating point arithmetic is also not allowed.
This is an extension of median of two sorted arrays of equal size problem. Here we handle arrays of unequal size also.