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

How to determine the complexity of python code?

I need to understand the complexity of the following code. I am familiar with the concepts of all the Big O() notation and also have read a lot of blogs but I cant figure how to apply to big programs. Following is the code for largest pallindrome…
harry r
  • 480
  • 1
  • 9
1
vote
1 answer

Can a problem be in NP but not NP-Complete or P?

I am looking at the graphs in: https://en.wikipedia.org/wiki/P_versus_NP_problem It seems like, there is gap between P and NP-complete. So are there a class of problems that are in NP but neither in P or NP-Complete. In other words, do the classes…
shreyasva
  • 11,896
  • 23
  • 73
  • 101
1
vote
2 answers

Longest non decrease subseq in Haskell is slow. How to improve?

longest'inc'subseq seq = maximum dp where dp = 1 : [val n | n <- [1..length seq - 1]] val n = (1 +) . filter'and'get'max ((<= top) . (seq!!)) $ [0..pred n] where top = seq!!n ----- filter'and'get'max f…
vpdp_pc
  • 13
  • 2
1
vote
0 answers

Lempel-Ziv encoding - split string

I have given string 1100011110000011111000000. I have to encode it by Basic Lempel-Ziv algorithm. I know how to do it. The problem is two first numbers are 1. I parse it into anordered dictionary of substrings. So result is: 1, 10, 0, 01, 11, 100,…
CodeCode
  • 11
  • 1
1
vote
1 answer

Counting and Complexity for Password Possibility

Each password should contain exactly 8 alphanumeric characters (0-9, a-z). The first and the last character of each password should be a number. The password must contain the 3-character string “TCO”. Explain how many unique passwords can be…
Edith DIth
  • 13
  • 3
1
vote
1 answer

Finding running time of the following code

public static int loop(int n){ int j = 1; int n2 = n; for (int i = 0; i < n; i++) { n2 *= 5.0/7.0; for (int k = 0; k < n2; k++) { System.out.println("Hello."); } } return j; } Hello all, I'm having some…
beyuma
  • 35
  • 1
  • 5
1
vote
2 answers

Accounting for time complexity of array insertion

Given an insertion sort on an array where you do O(n) comparisons to find the index to insert at, then insert, would the time complexity be O(n^3)? Since for each element (n), you iterate through the sorted list(n), then insert (n). From what I…
Danny
  • 77
  • 1
  • 6
1
vote
3 answers

Precise Input Size and Time Complexity

When talking about time complexity we usually use n as input, which is not a precise measure of the actual input size. I am having trouble showing that, when using specific size for input (s) an algorithm remains in the same complexity class. For…
1
vote
1 answer

Is the Language L := {a^nb^nc^n | n >= 1} in P?

L := {a^nb^nc^n | n >= 1} is not regular (Cannot be pumped). Yet i can easily find a 4-Tape deterministic Turing Machine that accepts L in polytime. Therefor L should be in P right?
yooloobooy
  • 136
  • 2
  • 8
1
vote
1 answer

complexity analysis of linear search in sorted array

Can anyone tell me that what will be the average time complexity of linear search when it is applied on a sorted array? I know worst case will be O(n) and best case will be O(1) but I dont know about average case in sorted array.
1
vote
1 answer

Expression that bounds Big O

T(n) = (n!n+n^3)(n^2+7logn) How to find the expression (constant) that bounds n!n^3 ?
1
vote
1 answer

Big O simplification of factorial

To calculate BigO and constant for the following function : I have don't know how to simplify it further. Any advise ? Thx T(n) = (n!n+n^3)(n^2+7logn) <= (n!n+n^3)(n^2 +7n) (since n>= log n) <= (n!n+n^3)(n^2 +7n) (n^3 >= 7n…
1
vote
1 answer

Asymptotic Notation: Proving Big Omega, O, and Theta

I have a few asymptotic notation problems I do not entirely grasp. So when proving asymptotic complexity, I understand the operations of finding a constant and the n0 term of which the notation will be true for. So, for example: Prove 7n+4 =…
Snyder-66
  • 19
  • 1
1
vote
1 answer

How summation of theta(1) over n times is theta(log n base 2)

If T(n) = theta(1) + theta(1) + theta(1) +...(n times)...+ theta(1) How, can we write T(n) = theta(log(n) base 2). How is 1+1+1+..+1 = log(n) base 2?
ABHISHEK DAS
  • 53
  • 1
  • 6
1
vote
1 answer

Looking for an efficient Interval tree Algorithm

I have a set of objects which store intervals given by the low and high value. I'm searching for a data struture, which will allow me to get all objects, whose intervals overlap with a given point in real-time. I also need to be able to add and…
LostBoy
  • 13
  • 2
1 2 3
99
100