Browsing the topic Misc
In the previous post, we discussed how Asymptotic analysis overcomes the problems of naive way of analyzing algorithms
Read More »Following are common definition of Binomial Coefficients. 1) A binomial coefficient C(n, k) can be defined as the coefficient of X^k in the expansion of (1 + X)^n.
Read More »Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order
Read More »Given a sequence of matrices, find the most efficient way to multiply these matrices together.
Read More »Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn’t matter.
Read More »Difficulty Level: Rookie Given a stream of numbers, print average (or mean) of the stream at every point. For example, let us consider the stream as 10, 20, 30, 40, 50, 60, … Average of 1 numbers is 10.00 Average of 2 numbers is 15.00 Average of 3 numbers is 20.00 Average of 4 numbers [...]
Read More »Given two integers k and n, write a function that prints all the sequences of length k composed of numbers 1,2..n. You need to print these sequences in sorted order.
Read More »Consider the following Java program:
Read More »Like C++, Java also supports copy constructor. But, unlike C++, Java doesn’t create a default copy constructor if you don’t write your own.
Read More »Question 1 Predict the output of the following program. What does the following fun() do in general?
Read More »The purpose of inheritance is same in C++ and Java. Inheritance is used in both languages for reusing code and/or creating is-a relationship. There are following differences in the way both languages provide support for inheritance.
Read More »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, n) from (0, 0). Each cell of the matrix represents a cost to traverse through that cell.
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 the screen
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 are considering the set contains non-negative values. It is assumed that the input set is unique (no duplicates are presented).
Read More »Design and Implement Special Stack Data Structure | Added Space Optimized Version
16 Comments | Filed under MiscQuestion: Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin()
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 to use % and / operators.
Read More »Question: We have discussed Naive String matching algorithm here. Consider a situation where all characters of pattern are different.
Read More »We have discussed Knight’s tour and Rat in a Maze problems in Set 1 and Set 2 respectively. Let us discuss N Queen as another example problem that can be solved using Backtracking.
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 solved using Backtracking.
Read More »Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that “works”. Problems which are typically solved using backtracking technique have following property in common.
Read More »Continuing further on dynamic programming series, edit distance is an interesting algorithm.
Read More »What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.
Read More »We have discussed Overlapping Subproblems and Optimal Substructure properties in Set 1 and Set 2 respectively.
Read More »We have discussed Overlapping Subproblems and Optimal Substructure properties in Set 1 and Set 2 respectively.
Read More »As we discussed in Set 1, following are the two main properties of a problem that suggest that the given problem can be solved using Dynamic programming.
Read More »