Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

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.

Filter by
Sorted by
Tagged with
4 votes
4 answers
2k views

I am reading Ousterhout's A Philosophy of Software Design. In Section 2.3, Outserhout writes: The signature of a method creates a dependency between the implementation of that method and the code ...
user3899725's user avatar
0 votes
1 answer
278 views

I recently changed my job to a big MNC and the code I am exposed to is highly complicated, difficult to read and understand. Although it is divided in microservices and runs on local I have to keep ...
Surya Saini's user avatar
1 vote
0 answers
146 views

I'm trying to solve the following problems here: In the X world, companies have a hierarchical structure to form a large binary tree network (can be assumed to be a perfect binary tree). Thus every ...
driver's user avatar
  • 111
2 votes
3 answers
329 views

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 ...
3366784's user avatar
  • 131
-3 votes
3 answers
212 views

In the Netflix series Suits, Season 1, Episode 8 (Identity Crisis), the legal team, with the help of a hacker, is tasked with proving that a business magnate embezzled funds, splitting them and ...
Cade Bryant's user avatar
0 votes
1 answer
133 views

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 ...
Frax's user avatar
  • 103
0 votes
0 answers
96 views

So I came upon this time complexity result and I was confused about it, it said that : O(nlogn) + O(logn) =O(log(n+1)) Why is that the case? Shouldn't the result be O(nlogn)?
blake 's user avatar
  • 27
0 votes
2 answers
395 views

In Daily Coding Problem, Miller&Wu have the following problem : Given an array of integers, return a new array where each element in the new array is number of smaller elements to the right of ...
molyss's user avatar
  • 181
0 votes
3 answers
727 views

Prompted by Sonar, I am looking to reduce the complexity of a function (one that some might call arrow code). I am loosely familiar with some of the principles of reducing arrow code complexity (...
j.k's user avatar
  • 111
-1 votes
1 answer
269 views

I have a two dimensional data with one dimension is ordered and another one is categorical, for example, country and city_age: country age city Italy 2773 Rome Germany 784 Berlin USA 397 New York ...
Dims's user avatar
  • 157
14 votes
3 answers
5k views

I recently asked a question on CodeReview SE where using a binary search was recommended, and the author of the answer proved that it was faster than my implementation. During my research on the topic,...
Taco's user avatar
  • 1,175
4 votes
1 answer
1k views

Mostly in all routers and operating systems the Longest Prefix Match algorithm is used for searching the trie of IPv4 addresses. Packet filters like Iptables don't need some special data structure for ...
red0ct's user avatar
  • 99
0 votes
2 answers
1k views

I am trying to calculate the time complexity of the below code snippet def func() { for(i=1; i<=n; i++) { for(j=1; j<=n; j=j+i) { print("hello") } }...
learnToCode's user avatar
3 votes
0 answers
570 views

I'm working on a application which uses event-sourcing and CQRS to define it's domain model. Background We have implemented projections to aggregate stream of all domain events into a read models used ...
Euphoric's user avatar
  • 38.2k
4 votes
5 answers
419 views

I have a disagreement with one of my colleagues on whether or not functions should have inverse functions available. I would like to know when/if inverse functions should be used. For example, say we ...
Byebye's user avatar
  • 346
5 votes
2 answers
2k views

Is it possible to find the closest point (or k closest points) to any arbitrary point in a set of n points (in dimension N)? When I write closest point, I mean smallest Euclidean distance. I'm looking ...
Fifi's user avatar
  • 159
0 votes
2 answers
114 views

Suppose we have a code: for(int i=0;i<n;i++) sum+=i; We say the time function here is: f(n) = n+1+n = 2n+1. The order of the time function is 1. So, our time complexity becomes O(n). But, for the ...
Md Mosleh Uddin's user avatar
0 votes
2 answers
124 views

My question is, knowing everything there is to know about several systems(CPU and GPU stats, OS), is it possible to approximate when each system will finish a specific processing operation? And if it ...
kasra's user avatar
  • 131
0 votes
2 answers
198 views

I have a program that calculates N digits of Pi. I have measured that it takes 10x time to calculate 3n numbers, compared with the time for calculating n numbers. The source code also gives an ...
15 Volts's user avatar
  • 127
0 votes
1 answer
204 views

I have an array of events where events[i] = [startDay_i, endDay_i, value_i]. The ith event starts at startDay_i and ends at endDay_i, Attending the ith event, I will receive value_i. Also given an ...
PSLove's user avatar
  • 23
-2 votes
1 answer
116 views

This code is from https://www.geeksforgeeks.org/segregate-even-and-odd-numbers/ It takes an array of numbers & segregates them in place without bothering about the order. void segregateEvenOdd(int ...
user93353's user avatar
  • 429
5 votes
4 answers
684 views

I have an n x n matrix which I need to convert into a list sorted by value. Starting with the maximum value cell at (row x1, col y1), I must immediately exclude all cells where (x >= x1, y <= y1)...
Irfan434's user avatar
  • 187
3 votes
3 answers
1k views

I started to play with C++ recently. One of the difficulties I have quite often is when the compiler tells that there is an issue with the types: more often than not, those compiler errors look ...
Arseni Mourzenko's user avatar
3 votes
1 answer
223 views

I am working through MIT 6.006 OpenCourseWare as taught in Fall 2011. Problem 1.2c asks for the time complexity of an algorithm1 which finds a peak element (i.e. all neighbors are less than or equal) ...
Lorem Ipsum's user avatar
21 votes
6 answers
5k views

I recently finished a course on advanced algorithms, and another on complexity & computability theory, and in the past few days my mind has been somewhat preoccupied by this question. Why don't we ...
cliesens's user avatar
  • 345
2 votes
2 answers
257 views

I'm trying to find the time complexity for the following code. N= number of elements in array D= a constant: D>1 V= a constant: V>1000 counter=1; //the maximum value of the counter is N/D. ...
Alice's user avatar
  • 37
-4 votes
1 answer
429 views

Please, consider the below merge sort algorithm. Here we start with a divide portion which splits the array into halves and we do recursive operation on each half separately. I have ignored the merge ...
Brisingr's user avatar
-2 votes
1 answer
113 views

Understood that for all these ways of measuring the time and space is dependant on the users hardware, I was wondering is there is a similar way to calculate the battery usage of a program over n ...
Sean's user avatar
  • 99
0 votes
0 answers
82 views

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 ...
yb212's user avatar
  • 1
0 votes
1 answer
257 views

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). ...
restin84's user avatar
4 votes
4 answers
2k views

It is my understanding that: It's particularly difficult to compile ahead of time, to efficient native machine code, a dynamically typed language like Python. Largely as a result of the above, the ...
Amelio Vazquez-Reina's user avatar
2 votes
1 answer
123 views

I have a scenario for which I'll take an analogous example to help understand better. There are N buckets of known varying capacities. We have M balls that we need to put in these buckets to fill ...
Varinder Singh's user avatar
14 votes
2 answers
5k views

Pseudo code and comments to explain: // first select companies to process from db foreach (company) { // select the employees foreach (employee of company) { // select items they can ...
Jesse Q's user avatar
  • 251
2 votes
0 answers
129 views

We have a project that is meant to do signal processing. If all we had to do with the software was that one job, we would have a pretty clean architecture. Unfortunately, we've run into an issue most ...
Krupip's user avatar
  • 1,347
-2 votes
1 answer
377 views

According to the Halstead's software metrics: Estimated program length: Can you please explain me, why the formula uses logarithm to base 2? Why not something else? Why exactly logarithm? What’s ...
Michael Abyzov's user avatar
4 votes
2 answers
2k views

Is the sum of the cyclomatic complexity of all section in a file the total cyclomatic complexity for this file? If it is, is the sum of a set of related files the total cyclomatic complexity for this ...
cervh's user avatar
  • 83
-1 votes
1 answer
147 views

I have this method arr // input new_ seq = [] for i in arr: new_seq.append(i) __new_seq = [x for i, x in enumerate(arr) if x not in new_seq] for j in __new_seq: new_seq.append(j) ...
Farah Amawi's user avatar
4 votes
1 answer
338 views

I am currently working on a project that has very little documentation overall. The team is working to change that. I am doing my part, by adding xml comments to the methods I make and the ones I edit,...
Kaito Kid's user avatar
  • 151
1 vote
3 answers
239 views

What time complexity would you classify the following as having? int n = 100; for(int x = 0; x < n; x++) for(int y = 0; y < n; y++) for(int z = 0; z < n; z++) DoWork(...
Eoin Campbell's user avatar
0 votes
1 answer
630 views

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 ...
NeutronStar's user avatar
1 vote
1 answer
488 views

I just started leaning about algorithm design and I am now having trouble identifying the additional space used in an algorithm. For dynamic program, as far as the examples I've learnt, such as ...
Fluffy Skye's user avatar
2 votes
2 answers
4k views

I was going through the traditional quick sort algorithm. I had a look on the partition algorithm in a couple of places and the implementation difference was very subtle. Here are the 2 approaches: ...
arnie7's user avatar
  • 33
5 votes
2 answers
2k views

Building my last application, everbody started to lose control over the increasing complexity of business rules, which would be added every week - most of all the app owners themselves. In the end, we ...
Hans's user avatar
  • 572
1 vote
2 answers
716 views

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 ...
Carlisle Manson's user avatar
-2 votes
1 answer
156 views

I'm comparing two APIs to generate a method in C# and want to measure how "complex" the code to use them is. Consider: API A: MethodDeclaration(PredefinedType(Token(IntKeyword)), "CompareTo") ....
svick's user avatar
  • 10.2k
0 votes
3 answers
107 views

I have two classes: public class Child { public List<Vector2> localPoints; public List<Vector2> localEdges; } public class Parent { public List<Child> children; ...
Tagor's user avatar
  • 169
12 votes
3 answers
878 views

In university, at our algorithms courses, we learn how to precisely compute the complexity of various simple algorithms that are used in practice, such as hash tables or quick sort. But now in a big ...
user7088941's user avatar
0 votes
1 answer
48 views

I am pretty confident that this is well-known and solved problem. Suppose there are n uniquely indexed "packages" randomly getting into single entry point like .AcceptPackage(Package package). ...
Zazaeil's user avatar
  • 345
0 votes
2 answers
2k views

From my book "Data Structures & Algorithms in Java: Sixth Edition" the definition of Big Oh is the following: Let f(n) and g(n) be functions mapping positive integers to positive real numbers. ...
Zimano's user avatar
  • 232
-2 votes
1 answer
39 views

Given an array A[N] of N booleans, return a, b such that a >= 0, b > 0 and A[a] = true A[a+b] = true A[a+2b] = true or -1 if they don't exist. The best algorithm I could find was brute forcing ...
user1247066's user avatar

1
2 3 4 5