how can I calculate the complexity algorithm for my algorithm?

I had developed a system for fruit grading whose steps are segmentation, feature extraction, classification. the dimension of image n*n Number of images m then segmented image has complexity O(m.n^2) IF (n.k is a segmented part) features are extracted then complexity after feature extraction is O(m.n.k) if p is the number of features extracted then complexity after classification is O(m.p) Total Complexity=o(m(n^2+n.k+p))

I want to ask for different segmentation technique used, different number of features, different classifier used what are the changes in total complexity

Complexity of the following function $ f(n) = 1000+\log_{2}(n^{9n})+3n\log_{1000}(n^{n}) $

I know that $ f(n) = 1000+\log_{2}(n^{9n})+3n\log_{1000}(n^{n}) \in O(n^2\log{n}) $ , but how can you derive this. I mean you choose the strongest increasing term with the $ n$ in it and then you remove all the constants and that is you complexity but I do not know how to derive the above function. Can someone help me out?

what will be space complexity for snippet for(i=1 to n) int x=10;?

The space complexity of the code snippet given below-

int *a=malloc(n*sizeof(int)); int sum=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); for(j=0;j<n;j++) { int x=a[i]; sum=sum+x; } } free(a); 

This is question of a test. I answered it O(n), considering space only for array and constant space for rest of the code. But in the answer they given O(n^2) and there explanation is "The array is of size n and the inner most loop we are declaring a variable x every time the loop is executed, this loop is executed O(n^2) time hence overall space complexity is O(n^2)." Now my doubt is what should be space complexity of

for(i=1;i<=n;i++)    int x=10; 

What i thought is that it should be O(1) because in each iteration variable x gets destroyed. Please someone help me…i searched but found nothing satisfactory.

Complexity of Subset Sum where the size of the subset is specified

I know it should be easy but I’m trying to determine the complexity of the following variant of Subset Sum.

Given a subset $ S$ of positive integers and integers $ k>0$ and $ N>0$ , is there a subset $ T\subset S$ such that $ |T|=k$ and the members of $ T$ sum to $ N$ ?

All of the formulations of subset sum that I’ve seen don’t specify $ k$ so I’m wondering if this problem can be solved in polynomial time. If $ k$ is fixed for all instances, then I know that the problem is in P and solvable by brute force in $ O(n^k)$ time. However, I’m allowing $ k$ to vary from instance to instance.

Communication complexity

Alice enjoys watching table tennis and in her local league there are n players, each of whom is assigned an identification number between 1 and n. • Unfortunately Alice had to leave before the end of the most recent match, so she knows the two player’s numbers but not the winner. • Bob does not watch table tennis but overheard the number of the winner of that most recent match (but not the number of the loser). Other than that he did not pay attention at all and knows nothing else. Give a communication protocol which allows Alice to discover the winner from Bob. You should argue both that your protocol is correct and also give an upper bound for the number of bits used in the worst case. Protocols using fewer bits will receive more marks (Θ(log n) bit protocols will get two marks).

Pleae help

About the complexity of deciding if the closed world assumption for renamable Horn CNF is consistent


Let $ T$ be a theory that only contains renamable horn formulas. What is the complexity of deciding if the closed world assumption $ CWA(T)$ is consistent?

The closed world assumption is defined as follows:

$ CWA(T):=T\cup \{\neg p : p\text{ is atom } T \not\models p\}$

Renamable horn formulas are CNF formulas that can be renamed to horn formulas by negating a variable in the formula for example

$ (x_1\vee x_2 \vee x_3)\wedge (\neg x_3 \vee\neg x_4)$

is not a horn formula but can be renamed by the renaming $ R=\{x_2,x_3\}$ to get the equally satisfiable formula

$ (x_1\vee \neg x_2 \vee \neg x_3)\wedge (x_3 \vee\neg x_4)$

My findings so far:

We call a theory $ \Phi$ of first order logic inconsistent if $ \exists \phi \in \Phi$ such that $ \Phi\models \phi$ and $ \Phi\not\models \phi$ . Otherwise $ \Phi$ is consistent.

To check whether $ CWA(T)$ is consistent it is sufficient to check if $ \Phi=\bigwedge_{\phi\in CWA(T)}\phi$ is satisfiable.

Algorithm to construct CWA:

To compute $ CWA(T)$ we need to know if $ T\models x_i$ for all variables in $ T$ . This can be done by considering $ \Psi=\bigwedge_{\psi\in T}\psi$ and then checking if $ \Psi \rightarrow x_i$ or equivalently $ \neg x_i \rightarrow \neg\Psi$ . Therefore if we set $ x_i=0$ in $ \Psi$ and $ \Psi$ is not satisfiable it follows $ T\models x_i$ , otherwise $ T\not\models x_i$ .

First create an set $ I=\{\emptyset\}$

For all variables defined by the index $ i=0,…,n$ we do the following calculation:

1.] set $ x_i=0$ in $ \Psi=\bigwedge_{\psi\in T}\psi$

2.] if $ \Psi$ is not satisfiable $ I=I\cup\{x_i\}$

By considering the elements of $ I$ we can conclude $ CWA(T)=T\cup\{\neg x_i:x_i\not\in I\}$ .

Deciding if CWA(T) is consistent is at least NP-hard:

let $ C_1,…,C_m$ be clauses of an arbitrary 3-SAT instance and $ C_{m+1}=(u\vee v)$ such that $ u,v$ are fresh atoms. Then $ T=\{C_1,…,C_m,C_{m+1}\}$ contains only renamable Horn clauses.

To decide if $ CWA(T)$ is consistent we need to decide if $ u$ is free for negation. This follows by checking if $ T\models u$ . Therefore we assume $ u=0$ and check if $ C_1\wedge C_2 \wedge … \wedge v$ is not satisfiable. Since v occurs in no other clause, the formula is not satisfiable if $ C_1\wedge … \wedge C_m$ is not satisfiable, but $ C_1\wedge … \wedge C_m$ is an arbitrary 3-SAT instance and so checking if $ CWA(T)$ is consistent is at least NP-hard.

How to determine if given “complex” time complexity is $O(n^2)$?

If a given time complexity, such as these:

  1. $ (n + \log n) * \sqrt{n+\log n}$
  2. $ n * (200 + \log^2 n)$
  3. $ (7+n^3)\log(n^5)$

is not determinable by just looking at it whether is it in class $ O(n^2)$ or not, how do I decide? If a time complexity is given, and in it there are more types of expressions (exponential, logarithmic, polinomial, … ) how do I decide which one determines the $ O(n^2)$ or $ O(n\log n)$ or … complexity?