# Category Archives: Algorithms

Given a cost matrix cost[][] and a position (m, n) in cost[][], write a function that returns cost of minimum cost path to reach (m,… Read More
Given that integers are read from a data stream. Find median of elements read so for in an efficient way. For simplicity assume, there are… Read More
Question 1 Consider the following recursive C function. Let len be the length of the string s and num be the number of characters printed on… Read More
Subset sum problem is to find subset of elements that are selected from a given set whose sum adds up to a given number K. We… Read More
Given a positive number n, write a function isMultipleof5(int n) that returns true if n is multiple of 5, otherwise false. You are not allowed… Read More
Given an unsorted array of size n. Array elements are in the range of 1 to n. One number from set {1, 2, …n} is… Read More
Question: We have discussed Naive String matching algorithm here. Consider a situation where all characters of pattern are different. Can we modify the original Naive… Read More
We have discussed Knight’s tour and Rat in a Maze problem in Set 1 and Set 2 respectively. Let us discuss N Queen as another… Read More
We have discussed Backtracking and Knight’s tour problem in Set 1. Let us discuss Rat in a Maze as another example problem that can be… Read More
Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that “works”. Problems that are typically solved using the backtracking technique have… Read More
Given two strings str1 and str2 and below operations that can be performed on str1. Find minimum number of edits (operations) required to convert… Read More
What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.  C++ void fun() {     int i, j;… Read More
Space Complexity: The term Space Complexity is misused for Auxiliary Space at many places. Following are the correct definitions of Auxiliary Space and Space Complexity.  Auxiliary… Read More
LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in… Read More
LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in… Read More