Questions tagged [complexity]

Complexity deals with various forms of calculating the complexity of code. Cyclomatic complexity, n-path complexity, Big O time and space complexity.

Complexity takes many forms within computing. Most often it is used as an attempt to measure either how hard something is to understand, or how long (or large) something will run.

The understanding complexities that are used most often are that of cyclomatic complexity which looks at the number of independent paths through some code, and n-path complexity (more often seen in static analyzers) that looks at the combination of all the different paths throughout the code.

Related reading:


The more theoretical complexity is that of big O and is used with the asymptotic behavior of either the time code will take to run, or the amount of memory it will use.

Related reading:

222 questions
18
votes
15 answers

Adding complexity by generalising: how far should you go?

Reference question: https://stackoverflow.com/questions/4303813/help-with-interview-question The above question asked to solve a problem for an NxN matrix. While there was an easy solution, I gave a more general solution to solve the more general…
moinudin
  • 371
12
votes
10 answers

How to differentiate between trivial and non-trivial software?

So what really makes a program trivial? 'Unless its trivial software' is used so often in programming discussions. I find it very vague in the sense that I can't really figure if 'something is essential because its non-trivial software' or 'its…
NVM
  • 699
3
votes
3 answers

Complexity analysis: Finding common members of unsorted arrays

I've been going over previous tech interviews I've had (got another one coming up). The problem Anyway, one question I had was... Given 2 unsorted arrays how would you find all of the common objects between them? Say I have array A and B. Worst…
2
votes
3 answers

Does looping through n items always result in O(n) time complexity?

Summary I saw a solution to a problem described as having O(c) Time complexity where c is the number of unique items in n. I don't understand why we can say the complexity is O(c) despite looping through all items. Example func foo(items: [Int]) { …
3366784
  • 131
2
votes
1 answer

How do I determine correctness of a codes complexity?

Given a piece of code, I may use one of many methods to determine the big O complexity of the code manually (runtime and memory). But, for a given piece of code, how do I determine whether what I found earlier is correct or not? Are there tools…
user87166
  • 555
1
vote
2 answers

What is name of this type of complexity?

What is complexity related to number of operations/interactions between objects within a system? as that number increases the programmer capability of understanding and maintaining the system degrade.
jimjim
  • 875
1
vote
2 answers

Modulo complexity within nested loop

i have following code: for ( int i = 1; i < n; i ++) for ( int j = 0; j < n*n; j ++) if (j % i == 0) for (int k = 0; k < j; k++) sum++; How would if (j % i == 0) affect the overall complexity? As k goes up to…
Don_M
  • 37
1
vote
1 answer

How to solve O (N log N) and more

I got following exercise: An algorithm takes 0.5 ms for input size 100. How large a problem can be solved in 1 min if the running time is the following: linear O (N log N) ... So the algorithm can process 100 items in 0.5 ms therefore…
Don_M
  • 37
1
vote
3 answers

What is the rule for simplicity over complexity?

We have a site which is hugely complex in its implementation. Conceptually, it is simple - a web-based catalog. But the implementation has become a multi-layered nightmare. Can anyone indicate a "rule of thumb" for measuring when something has…
1
vote
2 answers

Is it correct/useful to define Computational Complexity in this way?

I analyzed my algorithm and I deduced that in the best case it requires n^3 iterations while in the worst case it requires n^4 iterations. Then I asserted that my algorithm is in \Omega(n^3) and in \BigO(n^4). Is this assertion correct and…
HAL9000
  • 153
0
votes
1 answer

Divide et Impera and P vs NP

Disclaimer: this is not an attempt at solving P vs NP, but a way for me to better understand the problem. Let ¥(n) be the Subset sum problem, n being the number of inputs. Trivially, a brute force algorithm can solve ¥(n) in O(n2^n). Let's Divide et…
Frax
  • 103
0
votes
0 answers

Practical Understanding of Log a / Log b Running Time

Was wondering if someone could give a practical understanding of what it means for an algorithm to perform in (log a / log b) time? In other words, practically speaking for an algorithm to perform in nlogn time it would need to split a max of log n…
yb212
  • 1
0
votes
1 answer

Time complexity of an algorithm whose output does not scale linearly with the size of the input

Suppose I have a function CalculateOutput(n) which creates an array of size n and repeatedly modifies this array by iterating through every element from 0 to n - 1 (say this is done in linear time). When the array is in a particular order then the…
restin84
  • 19
  • 2
0
votes
1 answer

Question on complexity of Barnes-Hut algorithm

A common algorithm used in N-body gravitational calculations with large numbers of bodies (stars in a galaxy, galaxies in the universe, etc.) is the Barnes-Hut algorithm, which assembles particles into an octree for approximate bulk calculations of…
0
votes
1 answer

Execution time of an algorithm on faster computer?

An algorithm takes 1 second to execute a dataset of size N on a particular computer. Replace it with a computer that is 10 times faster. What will be the size of the dataset you can process in 1 second on the new computer if the execution time for a…
1
2