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

learn more… | top users | synonyms

-1
votes
1answer
25 views

Considerations when making data structure and algorithm choices

What are some reasons you may choose a worse runtime algorithm? And what are some advantages of a linked list vs a hash table/array where access is constant time.
5
votes
1answer
144 views

Is it possible to have these characteristics in a data structure?

I was tutoring a student that came up with this assignment. It basically requires a data structure with the following characteristics: it holds a set of integers in {1, 2, ..., n} n is power of 2 ...
4
votes
3answers
146 views

Trying to understand P vs NP vs NP Complete vs NP Hard

I am trying to understand these classifications and why they exist. Is my understanding right? If not, what? P is polynomial complexity, or O(nk) for some non-negative real number k, such as O(1), ...
1
vote
3answers
117 views

Is increasing codebase size and complexity worth it to make fully configurable?

I'm re-creating a web app (Google Apps Script) that i made a couple months ago, and decided that I wanted to make it fully configurable this time around. So that I don't have to go in any change any ...
6
votes
2answers
127 views

Does Time Complexity analysis factor for cache performance of an algorithm?

If I have an algorithm A. and it has fewer instructions than algorithm B. but performs worse on a CPU due to poor memory coalescing (and hence, poor CPU cache performance), does that factor into the ...
1
vote
1answer
39 views

Efficiently determining many-to-many subset relation

I'm doing market basket analysis. I have a set of transactions. Every transaction is a set of items that were bought. I then have a set of itemsets (i.e. a set of items) that I want to determine the ...
8
votes
1answer
1k views

Refactoring byzantine payment processing code on a limited budget [closed]

I've been working on a large Ruby on Rails application for several years. It was inherited in a poor state but most of the production bugs have been ironed out with time. There are some sections that ...
1
vote
2answers
252 views

How to write highly changeable, highly complex software? [closed]

I know questions like this has been asked before. But none of them truly answered me. How to keep a big and complex software product maintainable over the years? How do you organize highly customized ...
2
votes
1answer
90 views

Burrows-Wheeler transform backward search: how to find suffix index?

BWT backward search algorithm is pretty straightforward if we only need the multiplicity of a pattern. However I also need to find the suffix indices (i.e. positions in the reference string where a ...
-3
votes
1answer
77 views

complexity of an algorithm, sorting 5% out [duplicate]

I have been asked the following question.. An algorithm considers n elements, sorts 5% of n out, considers the remain elements(95%), sorts 5% of the remain elements, and so on until finally one last ...
1
vote
1answer
82 views

How to document GUI screens transitions of a complex application

There is an application based on multiple screen model with pretty complex net of transitions between these screens. It has some similarities to a web page or Football Manager like games. Its main ...
2
votes
1answer
141 views

Time Complexity when Loop Variable Depends upon Outer Loop Variable

What is the time complexity of the following piece of code in worst case? s = 0; for( i = 1; i <= n; ++i ) { for( j = 1; j <= i * i; j++ ) { for( k = 1; k <= j and j % i == 0; ...
1
vote
3answers
222 views

What's the big-O complexity of this recursive algorithm?

I am following a course of Algorithms and Data Structures. Today, my professor said the complexity of the following algorithm is 2^n. I waited till the lesson was over, approached him and told him ...
4
votes
2answers
108 views

Check in which region is a geoposition Marker located in

I use Mapbox to display some moving markers over a map with several polygons drew over it (feature layers). I have serveral markers (~1000) and multiple feature layers (polygons ~200) that represent ...
1
vote
1answer
44 views

How an add vertex operation could be performed in constant time for a graph represented using adjacency list?

Adding a vertex in a graph that is represented using an adjacency list takes O(1) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency list > add vertex). It is said ...
3
votes
1answer
137 views

why adding a vertex in a graph represented using an adjacency matrix takes O(|v|^2) time complexity?

Adding a vertex in a graph that is represented using an adjacency matrix takes O(|v|^2) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency matrix > add vertex). But ...
9
votes
4answers
736 views

Reducing the complexity of a class

I have looked at some answers and searched on Google, but I could not find anything helpful (i.e., that wouldn't have awkward side effects). My problem, in abstract, is that I have an object and need ...
5
votes
3answers
537 views

Is O(log n) + O(log n) = O(n)? [duplicate]

We know that binary search takes O(log n) in Big O notation but if we need to run twice an algorithm of O(log n), would it be the same as O(n) in time complexity? For example, if I have a method to ...
2
votes
1answer
65 views

Time complexity of update and lookup in binary random access list

I'm trying to get through one of the exercises in Okasaki's "Purely Functional Data Structures," where he presents a zeroless binary numbers as a structure for random-access list, and asks to 9.6 ...
6
votes
3answers
173 views

Why don't “multi-infinite” list comprehensions work with lazy evaluation?

As a simple demonstration of the efficiency of Haskell style, I thoughtlessly ran the following: take 100 [(a, b, c) | a <- [1..], b <- [1..], c <- [1..], a^2 + b^2 == c^2] This should be a ...
-5
votes
3answers
488 views

How can the containsKey() method of a Java Hash Table be O(1)? [duplicate]

I had a very large ArrayList in Java, and I often need to check if it contains a particular value. This has proven very slow. Then I discovered that you can use a data structure based on a Hash. ...
3
votes
1answer
146 views

What is the time complexity of this program?

An algorithm is given on GeeksForGeeks.com for constructing a Binary Search Tree from its preorder traversal. They say that the time complexity for the following code is O(n^2). But in my opinion it ...
2
votes
1answer
78 views

Seeds distribution algorithm with complexity better than O(n^3)?

I have included my approach and solution. My solution works fine, however, is unoptimized with O(n^3) complexity An NGO is running seed distribution program. It has limited quantity of varied quality ...
1
vote
2answers
467 views

Efficiently find whether Binary Search Tree is Height Balanced or not?

A binary tree is height balanced if and only if the two subtrees of root are height balanced and the difference between the two subtrees height is at most 1. I implemented a code in java to find ...
15
votes
4answers
1k views

Are Constant Time and Amortized Constant Time effectively considered equivalent?

I need to write a RandomQueue that allows for appends and random removal in Constant Time ( O(1) ). My first thought was to back it with some kind of Array (I chose an ArrayList), since arrays have ...
-3
votes
4answers
175 views

Time complexity of this loop [duplicate]

Is the time complexity for this loop O(n) or O(log n)? for(i=0;i<n/2;i++){} I am thinking, the time is proportional with the input size.
1
vote
1answer
274 views

What are the time and space complexities of this recursive method that reverses a singly linked list?

What are the Time and Space complexities of this Java method that reverses a singly linked list (of length n)? I'm more interested in knowing the reasoning behind the space complexity. Let me know if ...
0
votes
1answer
65 views

Do Temporary tables have any form of index in SQL?

Consider a simple query like this: SELECT * FROM DATA JOIN ( SELECT * FROM DATA )TEMPORARY_DATA ON TEMPORARY_DATA.DATA_IDN = DATA.DATA_IDN What is the performance of this? Is it O(n2) because ...
2
votes
1answer
97 views

Find all factors(prime and composite) of a number

We can find all the prime factors using a Sieve of Erastothenes. But how do we find ALL the factors of a number? For instance, 24 = 2x2x2x3 But the complete factor list is - 1,2,3,4,6,8,12,24. I am ...
-3
votes
1answer
130 views

Big O notation for a sub linear algorithm [duplicate]

I have a function for which the complexity raise by the square ten of the exponent of the number. Ex: +-----+----------+ |Input|Complexity| +-----+----------+ |0 | 1 | |10 | 2 | ...
2
votes
2answers
293 views

Finding the first subarray that sums to a given total

Due to the failure of comprehension of the last version here is the question. Given and unordered array of positive and negative integers. How can you find the first subarray to sum to a given ...
2
votes
3answers
145 views

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 ...
1
vote
0answers
72 views

A fast algorithm for a simple multi-objective minimization?

I have a set of n (arbitrary) integer numbers S which I want to partition into k subsets S_i each of size n/k (you can assume that k divides n). Let A be the arithmetic mean of elements of the set S. ...
1
vote
4answers
152 views

What do polynomial algorithms entail?

From here, I know it is that an algorithm that... ...is said to be solvable in polynomial time if the number of steps required to complete the algorithm for a given input is O(n^k) for some ...
1
vote
1answer
255 views

Why does this algorithm work in O(n m)?

This is from a blog post on Codeforces. I couldn't really understand why the editorialist goes on to claim that this code works in O(n m) This is a graph problem, where we are supposed to find the ...
2
votes
1answer
82 views

If I replace N objects with N pointers, is my space complexity still O(N)?

Lets say I get N objects as input, and I need to rearrange them into a different data structure. This means the space complexity of my algorithm will be O(N). But what if I replace the objects with ...
58
votes
6answers
6k views

Why aren't there code overviews for open-source projects? [closed]

There are very complex open source projects out there, and to some of them I think I could make some contributions, and I wish I could, but the barrier to entry is too high for a single reason: for ...
0
votes
1answer
145 views

What is the justification for the running time of this loop?

I don't understand why the running time of the following loop is n+2 ? Also why the running time of the statements inside the loop is n+1 ? Double test(int n){ int sum=0; -> 1 time ...
1
vote
3answers
223 views

What is the rule for simplicity over complexity? [closed]

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 ...
16
votes
16answers
2k views

Do else blocks increase code complexity? [closed]

Here is a very simplified example. This isn't necessarily a language-specific question, and I ask that you ignore the many other ways the function can be written, and changes that can be made to it.. ...
190
votes
16answers
33k views

What's wrong with comments that explain complex code?

A lot of people claim that "comments should explain 'why', but not 'how'". Others say that "code should be self-documenting" and comments should be scarce. Robert C. Martin claims that (rephrased to ...
1
vote
2answers
200 views

How to know whether to create a general system or to hack a solution

I'm new to coding , learning it since last year actually. One of my worst habits is the following: Often I'm trying to create a solution that is too big , too complex and doesn't achieve what needs ...
8
votes
2answers
1k views

single for-loop runtime explanation problem

I am analyzing some running times of different for-loops, and as I'm getting more knowledge, I'm curious to understand this problem which I have still yet to find out. I have this exercise called "How ...
1
vote
0answers
202 views

Complexity limits of solutions created in Google Spreadsheets

I am creating a solution where I essentially put all rules regarding communication with customers (including automatic invoicing, reminder emails, welcome emails, etc.) into a Google Sheets and use ...
0
votes
1answer
964 views

Complexity of ArrayList of LinkedHashSet

I get input strings from the console like this: while ((currentLine = bufferedReader.readLine()) != null ) { StringTokenizer string = new StringTokenizer(currentLine, " "); while ...
0
votes
3answers
241 views

Is there a common programming term for the problems of adding features to an already-featureful program?

I'm looking for a commonly used programming term to describe a software-engineering phenomenon, which (for lack of a better way to describe it) I'll illustrate first with a couple of ...
3
votes
5answers
357 views

Simplicity-efficiency tradeoff

The CTO called to inform me of a new project and in the process told me that my code is weird. He explained that my colleagues find it difficult to understand due to the overly complex, often new ...
0
votes
1answer
133 views

Time complexity implications when designing shell scripts for large data/high number of files?

There are many questions about the performance of commands or scripts on the U+L SE asset. As time is of the essence, this is often evaluated using the bash time reserved word or the external time ...
-1
votes
3answers
204 views

Is there a metric that can be equated to complexity in laymens terms? [closed]

Often times users cannot comprehend the complexity of software. They think that because a problem is easy to describe then it is easy to solve. I want to equate the complexity of a "simple program" ...
1
vote
1answer
149 views

How to implement an algorithm out-of-core?

I want to implement a parallel clustering algorithm "out-of-core" in CUDA. My CPU has 12GB of RAM and GPU has 4GB of it. What I want is that the entire dataset should be on the disk, and I can pick ...