Questions tagged [complexity-theory]

Computational complexity theory is a branch of the theory of computation in theoretical computer science and mathematics that focuses on classifying computational problems according to their inherent difficulty. Particularly common in programming is *amortized analysis* for time or space

Given a problem and a computational model, the complexity of the problem with respect to the model is a function of the input size. Complexity functions may measure different quantities, such as time or space:

  • The time complexity measures how much time is required by the model to solve the problem, given an input.
  • The space complexity measure how much memory space is required by the model to solve the problem, given an input.

As a measure, the complexity can be defined as a function:

c = f(n)

where n is the input size.

Usually, the complexity is classified with the analytical form of f(n). For example, if f(n) = n, the complexity is linear with respect to n; if f(n) = n2, the complexity is quadratic; and, if f(n) = 2n, the complexity is exponential.

3530 questions
1
vote
1 answer

Time complexity of nested loop where the second loop iterates only for the last iteration of the above loop

Imagine a scenario where the second loop is iterated once for each iteration of n except the last one where it is iterated m times: // n and m are two different variables. for(int i=0; i
Monke
  • 35
  • 9
1
vote
1 answer

Whats the difference between indexed retrieval and keyed retrieval

Looking at the docs for KeyedCollection i read the following:: The KeyedCollection class provides both O(1) indexed retrieval and keyed retrieval that approaches O(1).…
sommmen
  • 2,980
  • 1
  • 12
  • 23
1
vote
2 answers

Time complexity of Loops with If statements

If I have a loop like this: for(int i=0;i
itskarad
  • 75
  • 6
1
vote
1 answer

Asymptotic bounds and Big Θ notation

Suppose that f(n)=4^n and g(n)=n^n, will it be right to conclude that f(n)=Θ(g(n)). In my opinion it's a correct claim but I'm not 100% sure.
DKO2306
  • 13
  • 4
1
vote
1 answer

Time Comp: Why is a single for loop with three assignment statements twice as fast as three sequential for loops each with one assignment statement?

Why is try1 twice as fast as try2? Are these functions not both O(n)? Is the difference in execution time solely due to overhead? I am new to programming and am teaching myself algorithms and data structures through Python. According to the text I…
jpVCWC
  • 11
  • 2
1
vote
1 answer

Big-O notation: do I need to use induction, and are limits preferred?

So I have a course on algorithms next semester and I am trying to prepare for it. I am starting out with a asymptotic analysis. The book seems to state as long as I can find a constant C and some number n > no, where f(x) <= C*g(x), then I can…
1
vote
1 answer

Understanding Poly-time Reduction/NP-complete

Hi there, I am having trouble understanding the relation of X and Y when problem X is reducible to Y. In the question in the picture, I especially don't understand why a and b are not correct, if X is no harder than Y, then Y is at least as hard…
Fores
  • 15
  • 3
1
vote
1 answer

Determine time complexity of arithmetic progression

I am novice in analysing time complexity.some one can help me with the time complexity of below algorithm? public void test(int n) { for(int i=1;i<=n;i=i+2) { for(int j=1;j<=i;j++) {} } } outer loop will run n/2 times.Inner loop…
nayak0765
  • 101
  • 8
1
vote
1 answer

Trying to calculate the time complexity of the following piece of code

Is the time complexity of the following piece of code O(n^5)? My reasoning is that the outer for loop is O(n), the middle for loop is O(n^2) since the value of i is based on the value of n, and the inner for loop is O(n^2) since the value of j is…
1
vote
3 answers

What is the time complexity of below geometric series?

1) ....+n/16+n/8 + n/4+ n/n..=? 2) ...+n/5+n/4 + n/3+n/2...n/n..=? I am working on finding time complexity of few algorithms where i came across few geometric series. I believe 1st geometric series has log(n) .What is time complexity of 2nd…
nayak0765
  • 101
  • 8
1
vote
1 answer

Space complexity of function

I'm new to working out space complexity and am stuck working out the following function const isUnique = string => { if (string.length > 128) { return false } let seen = new Set() for (let i = 0; i < string.length; i++) { …
Andy
  • 103
  • 10
1
vote
0 answers

Karp-Reduction: Vertex Cover to Half Vertex Cover

I need to find a reduction for the next problems: Vertex Cover- Given (G=(V, E), k)-> G is undirected graph and we need S (subgroup of V) in size k that covers all the edges in E. Hal Vertex Cover- Given (G=(V', E'), k')-> G is…
1
vote
1 answer

Time complexity for detecting a cycle in a graph

I am trying to understand the time complexity of some efficient methods of detecting cycles in a graph. Two approaches for doing this are explained here. I would assume that time complexity is provided in terms of worst-case. The first is…
1
vote
1 answer

Determine time complexity when loop has multiplication factor

I am newbie in time complexity.Probably the question may be very easy. public void test(int n) { for(int i=1;i<=n;i=i*5) { System.out.println(i); } } Above code has one loop and the frequency of the loop is determined by (i=i*5). Can…
1
vote
1 answer

Proof of closure of asymptotically bounded functions under addition

I would like to prove this statement: If f(n) is Theta(h(n)) and g(n) = O((h(n)) then f(n) + g(n) is O(h(n)). All functions are assumed to be non-negative and monotonically non-decreasing. My attempted proof explains that if f(n) and g(n) are…
bollock1
  • 55
  • 7
1 2 3
99
100