complexity

How to solve the recurrence equation T(n)=T(n/2)+T(n/4)+\Theta(n)?

How to solve the recurrence equation 1.T(n)=T(n/2)+T(n/4)+\Theta(n) 2.T(1)=1 Use Big-Theta notation to give the result ...

How to understand the knapsack problem is NP-complete?

We know that the knapsack problem can be solved in O(nW) complexity by dynamic programming. But we say this is a NP-complete problem. I feel it is hard to understand here. (n is the number of items. W is the maximum volume.) ...

Complexity of sampling from mixture model...

I have a model where state j among M states is chosen with probability p_j. The probability could be any real number. This specifies a mixture model over the M states. I can access p_j for all j in constant time. I want to make a large number (N) of random samples. The most obvious algorithm is 1) Compute the cumulative probability dis...

For TestNG, what is the proper method for pre-populating the data source containing a complex model when it will be queried using Hibernate?

I wish to write tests for our Seam Framework-based web site's internal search engine that uses Hibernate + Lucene indexing (on DB2) for queries. What is the best solution for populating the data source before the TestNG suite is run when the project's data model is quite complex considering entity relationships and field constraints? For...

Easiest way to determine time complexity from run times

Lets suppose I am trying to analyze an algorithm and all I can do is run it with different inputs. I can construct a set of points (x,y) as (sample size, run time). I would like to dynamically categorize the algorithm into a complexity class (linear, quadratic, exponential, logarithmic, etc..) Ideally I could give an equation that more...

Unstructured and not-documented software with bugs and problems

Some time ago I started to develop an application. I had to learn how to do it, so I started with testing pieces of code, modules and libraries. From this testing stage I assembled many pieces that worked okay until the application did almost what it needed to do. However, very often I ran into exceptions, bugs, trouble, memory issues et...

Is an If branch that does nothing a code smell or good practice?

I've responded to threads here (or at least commented) with answers containing code like this, but I'm wondering if it's good or bad form to write a series of if branches with one (or more) of the branches doing nothing in them, generally to eliminate checking for null in every branch. An example (C# code): if (str == null) { /* Do not...

Recurrence Relation for a loop

The question is to set up a recurrence relation to find the value given by the algorithm. The answer should be in teta() terms. foo = 0; for int i=1 to n do for j=ceiling(sqrt(i)) to n do for k=1 to ceiling(log(i+j)) do foo++ ...

C++ : complexity of the implementation of exp in cmath and real cost of the cost of a call compared to a floating point operation ?

[I globally edited the question to be more "useful" and clear] Hello all, I was wondering about the complexity of the implementation of the function exp in cmath. By complexity, I mean algorithmic complexity if possible. Otherwise cost compared to a floating point operation (addition for example) The following lines : double x = 3; ...

Sort an array which is partially sorted

I am trying to sort an array which has properties like it increases upto some extent then it starts decreasing, then increases and then decreases and so on. Is there any algorithm which can sort this in less then nlog(n) complexity by making use of it being partially ordered? array example = 14,19,34,56,36,22,20,7,45,56,50,32,31,45.......

Complexity of Set operations

This is what I am doing: String one = "some string" String two = "some string" I want to know all the characters that are in string one and two and they should come in order as they are in string one I wrote a Java program which by using Collections performs set operations on both the collection. What I would like to know that what...

Help In Learning Algorithm Basics

Hi Guys, I am learning algorithms and need you guys to help me. I am a beginner so forgive me if my question is not clear. Whiles am learning i am seeing something like NlogN, N^2 etc.. and something like that. I don't really understand it clearly when it comes to checking the efficiency/performance of different algorithms using these...

complexity about going from beginning to end and back through a vector

Hi All I am trying to be familiar with the complexity evaluation of algorithms. In general I think that is a good/elegant practice, but in the specific I need it to express time complexity of my C++ code. I have a small doubt. Suppose I have an algorithm that just reads data from the beginning of a std::vector until the end; then it ...

Is there an algorithm to find the best set of Pairs of vertices in a weighted graph without repetition?

Is there any efficient algorithm to find the set of edges with the following properties, in a complete weighted graph with an even number of vertices. the set has the smallest, maximum edge weight for any set that meats the other criteria possible every vertex is connected to exactly one edge in the set All weights are positive dI c...