complexity-theory

What are NP problems?

回眸只為那壹抹淺笑 提交于 2019-12-11 04:06:39
问题 I read the article on wikipedia but could not understand what exactly are NP problems. Can anyone tell me about them and also what is relation of them with P Problems? 回答1: NP problems are problems that given a proposed solution, you can verify the solution in a polynomial time. For example, if you have a list of University courses and need to create a schedule so that courses won't conflict, it would be a really difficult task (complexity-wise). However, given a proposed schedule, you can

Calculate the complexity of a nested for loop

坚强是说给别人听的谎言 提交于 2019-12-11 03:36:45
问题 I want to calculate the complexity of this nested for loop: s = 0; for(i=1; i<=n; i*=2) for(j=1; j<=i; j*=2) s++; What strategy do I use to find the Big O complexity of this piece of code? 回答1: The outer loop marches through 1, 2, 4, 8, ... n , which takes O(lg n ) steps because you can only double one O(lg n ) times until you hit n . The inner loop does the same. It only goes up to i , but in the final iteration of the outer loop, i reaches its maximum value which is again n , so that's also

Big Omega notation - what is f = Ω(g)?

半城伤御伤魂 提交于 2019-12-11 03:31:38
问题 I've been trying for the better part of an hour to find reference to the following: f = Ω(g) But I have had no luck at all. I need to answer a question for an assignment and I can't find references. The assignment is basically asking me to indicate what it ( f = Ω(g) ) means, in the context of the following choices: f = Ω(g(n)) g = o(ln n) g = o(g(n)) g = O(f) f = O(g) Initially, I thought that perhaps there is an error in the question. I know option 1 is wrong and assume option 5 is also

Using the FFT algorithm to calculate

早过忘川 提交于 2019-12-11 03:27:42
问题 Given a set of n particles electric charge carriers founds on the points (1,0), (2,0), .... (n,0) on a plane. The particle charge that found in point (i,0) is noted as Qi. the force that act on the particle is given by the formula: C is a Coulomb's constant. Give an algorithm to calculate Fi, for all of the particles in total complexity O(nlgn). Hint: use FFT algorithm. It seems that Fi is already divided to the even and odd points.. I thought about to divide each sum to calculate the FFT

McCabe's cyclomatic complexity

牧云@^-^@ 提交于 2019-12-11 03:15:39
问题 To calculate the cyclomatic complexity of a code, I drew a control flow chart consisting of nodes and edges which helped me to calculate V (G) = E - N + 2 In my case E = 15 and N = 11. Resulting in a cyclomativ complexity of 6. Now to confirm my answer I would like some help on finding linearly independent paths for the code blow: int maxValue = m[0][0]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if ( m[i][j] > maxValue ) { maxValue = m[i][j]; } } } cout << maxValue << endl;

I am looking for an algorithm that calculates the power of a number. (x^y), x and y are integers . It must be of complexity O(log[n]))

纵然是瞬间 提交于 2019-12-11 02:58:15
问题 Currently, my best effort has resulted in complexity O(log[n]^2): int power(x,n) { int mult=1, temp=x, i=1, j=1; while (n>1) { mult=mult*x; x=temp; for (i=1;i<=log[n];i++) { x=x*x; j=j*2; } n=n-j; i=1; j=1; } if (n==1) return (mult*temp); return (mult); } P.S Thank you funkymushroom for helping me with my bad English :) 回答1: The idea behind implementing this operation in logarithmic time is to use the following (mathematical) equivalences (here n/2 denotes integer division): x^0 = 1 x^n = (x

Does multiplication take unit time?

有些话、适合烂在心里 提交于 2019-12-11 02:35:58
问题 I have the following problem Under what circumstances can multiplication be regarded as a unit time operation? But I thought multiplication is always considered to be taking unit time. Was I wrong? 回答1: It depends on what N is. If N is the number of bits in an arbitrarily large number, then as the number of bits increases, it takes longer to compute the product. However, in most programming languages and applications, the size of numbers are capped to some reasonable number of bits (usually

Big O vs Small omega

☆樱花仙子☆ 提交于 2019-12-11 02:04:13
问题 Why is ω(n) smaller than O(n)? I know what is little omega (for example, n = ω(log n) ), but I can't understand why ω(n) is smaller than O(n). 回答1: Algorithmic complexity has a mathematic definition. If f and g are two functions, f = O(g) if you can find two constants c (> 0) and n such as f(x) < c * g(x) for every x > n . For Ω , it is the opposite: you can find constants such as f(x) > c * g(x) . f = Θ(g) if there are three constants c , d and n such as c * g(x) < f(x) < d * g(x) for every

Find an upper and lower bound of following code

混江龙づ霸主 提交于 2019-12-11 00:23:32
问题 I need to find a closest upper and lower bound of following code. I am beeginer in this so sorry for my mistake. Upper bound for p() is O(log(n)), and lower bound is O(1) Upper bound for notp() is O(log(n)), and lower bound is O(1) I think that lower bound is O(1) because if I have n=4 then I get in the loop and since n%i==0 I call p() and it notice that is not a prime number so O(1) then since i=2 the other notp would not be executed. That is bast case scenario. Worst case scenario that I go

How to know if your Unit Test Fixture is “right-sized”?

那年仲夏 提交于 2019-12-10 21:26:03
问题 How do you know if you "Test Fixture" is right-sized. And by "Test Fixture" I mean a class with a bunch of tests in it. One thing that I've always noticed with my test fixtures is that they get to be kind of verbose; seeing as they could also be not verbose enough, how do you get a sense of when your unit tests are the right size? My assumption is that (at least in the context of web development) you should have one test fixture class per page. I know of a good quote for this and it's: