Questions tagged [asymptotics]

Questions about asymptotic notations and analysis

Asymptotic analysis is a method of describing the limiting behavior. It is used widely in computer science, particularly in analyzing the asymptotic behavior of algorithms and computational processes.

Related tags:

1483 questions
102
votes
3 answers

How does one know which notation of time complexity analysis to use?

In most introductory algorithm classes, notations like $O$ (Big O) and $\Theta$ are introduced, and a student would typically learn to use one of these to find the time complexity. However, there are other notations, such as $o$, $\Omega$ and…
98
votes
11 answers

Solving or approximating recurrence relations for sequences of numbers

In computer science, we have often have to solve recurrence relations, that is find a closed form for a recursively defined sequence of numbers. When considering runtimes, we are often interested mainly in the sequence's asymptotic growth. Examples…
70
votes
9 answers

Are there any problems that get easier as they increase in size?

This may be a ridiculous question, but is it possible to have a problem that actually gets easier as the inputs grow in size? I doubt any practical problems are like this, but maybe we can invent a degenerate problem that has this property. For…
dsaxton
  • 933
  • 6
  • 9
56
votes
5 answers

How is this sorting algorithm Θ(n³) and not Θ(n²), worst-case?

I just starting taking a course on Data Structures and Algorithms and my teaching assistant gave us the following pseudo-code for sorting an array of integers: void F3() { for (int i = 1; i < n; i++) { if (A[i-1] > A[i]) { …
54
votes
4 answers

What is the meaning of $O(m+n)$?

This is a basic question, but I'm thinking that $O(m+n)$ is the same as $O(\max(m,n))$, since the larger term should dominate as we go to infinity? Also, that would be different from $O(\min(m,n))$. Is that right? I keep seeing this notation,…
Zeus
  • 1,712
  • 1
  • 13
  • 15
49
votes
4 answers

How do O and Ω relate to worst and best case?

Today we discussed in a lecture a very simple algorithm for finding an element in a sorted array using binary search. We were asked to determine its asymptotic complexity for an array of $n$ elements. My idea was, that it is obvisously $O(\log n)$,…
48
votes
10 answers

O(·) is not a function, so how can a function be equal to it?

I totally understand what big $O$ notation means. My issue is when we say $T(n)=O(f(n))$ , where $T(n)$ is running time of an algorithm on input of size $n$. I understand semantics of it. But $T(n)$ and $O(f(n))$ are two different things. $T(n)$ is…
doubleE
  • 591
  • 1
  • 4
  • 8
41
votes
6 answers

Sorting functions by asymptotic growth

Assume I have a list of functions, for example $\qquad n^{\log \log(n)}, 2^n, n!, n^3, n \ln n, \dots$ How do I sort them asymptotically, i.e. after the relation defined by $\qquad f \leq_O g \iff f \in O(g)$, assuming they are indeed pairwise…
JAN
  • 619
  • 1
  • 6
  • 10
41
votes
4 answers

What is the name the class of functions described by O(n log n)?

In "Big O", common notations have common names (instead of saying, "Oh of some constant factor"): O(1) is "Constant" O(log n) is "Logarithmic" O(n) is "Linear" O(n^2) is "Quadratic" O(n * log n) is ??? Is it just "n log n" or does it have a special…
GlenPeterson
  • 545
  • 1
  • 4
  • 10
33
votes
2 answers

How asymptotically bad is naive shuffling?

It's well-known that this 'naive' algorithm for shuffling an array by swapping each item with another randomly-chosen one doesn't work correctly: for (i=0..n-1) swap(A[i], A[random(n)]); Specifically, since at each of $n$ iterations, one of $n$…
29
votes
5 answers

Is O(mn) considered "linear" or "quadratic" growth?

If I have some function whose time complexity is O(mn), where m and n are the sizes of its two inputs, would we call its time complexity "linear" (since it's linear in both m and n) or "quadratic" (since it's a product of two sizes)? Or something…
user541686
  • 1,187
  • 1
  • 10
  • 17
29
votes
1 answer

Asymptotics of the number of words in a regular language of given length

For a regular language $L$, let $c_n(L)$ be the number of words in $L$ of length $n$. Using Jordan canonical form (applied to the unannotated transition matrix of some DFA for $L$), one can show that for large enough $n$, $$ c_n(L) = \sum_{i=1}^k…
27
votes
2 answers

Data structure with search, insert and delete in amortised time $O(1)$?

Is there a data structure to maintain an ordered list that supports the following operations in $O(1)$ amortized time? GetElement(k): Return the $k$th element of the list. InsertAfter(x,y): Insert the new element y into the list immediately after…
A T
  • 978
  • 1
  • 9
  • 21
27
votes
2 answers

Understanding of big-O massively improved when I began thinking of orders as sets. How to apply the same approach to big-Theta?

Today I revisited the topic of runtime complexity orders – big-O and big-$\Theta$. I finally fully understood what the formal definition of big-O meant but more importantly I realised that big-O orders can be considered sets. For example, $n^3 + 3n…
mariaprsk
  • 411
  • 6
  • 7
26
votes
7 answers

Justification for neglecting constant factors in Big O

Many a times if the complexities are having constants such as 3n, we neglect this constant and say O(n) and not O(3n). I am unable to understand how can we neglect such three fold change? Some thing is varying 3 times more rapidly than other! Why do…
gpuguy
  • 1,819
  • 3
  • 22
  • 32
1
2 3
98 99