Questions tagged [code-complexity]

Code complexity is measure of the degree of complexity in code.

It is influenced by numerous factors such as: Average Hierarchy Height, Average Number of Derived Classes, Afferent Coupling, Efferent Coupling, number of “if” condition statements, and many others. Computer scientists have been measuring code complexity for decades. A widely used and intuitive measure is cyclomatic complexity, introduced in 1976.

191 questions
5
votes
4 answers

Reducing the complexity of an o(n^3) c++ code

I would like to reduce the complexity of the following algorithm. Basically, it takes a word as an input and calculates the number of unique letters within it (the "entropy" of the word). My current solution employs 3 embedded for loops, which comes…
5
votes
2 answers

What are the parameters used to calculate complexity in SourceMonitor?

I recently started using SourceMonitor to review my (and others) code. Though I understand other parameters judged by the tool, I don't know how does it calculates the complexity of the code. As in, what all parameters does it considers to read to a…
Manish Basantani
  • 16,931
  • 22
  • 71
  • 103
4
votes
1 answer

Is big O notation used to denote something other than the asymptote of a worst case performance?

I've come across the notation recently am confused by what I see. My previous understanding is that big O is supposed to be used to denote an upper bound whereas lower or tight bound uses different notations entirely (omega and theta respectively).…
4
votes
2 answers

In JavaScript, is there a word to describe a JSON-serializable object?

I'm looking for a term for simple objects that emphasizes their simplicity. Specifically, objects that are free of self-reference, and contain no methods, bindings, etc (i.e. JSON-serializable). Right now I use words like: "flat object" "simple…
kdbanman
  • 10,161
  • 10
  • 46
  • 78
4
votes
2 answers

OCLint generate html report

I'm trying to generate an html report from OCLint analysis. I've installed xctool and generate the json file with this command: xctool -project demoProject.xcodeproj -scheme demoProject -sdk iphonesimulator -reporter…
TheObjCGuy
  • 687
  • 6
  • 15
3
votes
2 answers

Convenient complexity for Stream API usage?

I have JSON document which is a result of parsing for a bunch of files: { "offer": { "clientName": "Tom", "insuranceCompany": "INSURANCE", "address": "GAMLE BONDALSVEGEN 53", "renewalDate": "22.12.2018", "startDate":…
catch23
  • 17,519
  • 42
  • 144
  • 217
3
votes
2 answers

Make code less complex and more readable

I need to rewrite my simple code. I'm getting simple strings as below: Distrib ABC 1-2-x Distrib ABC DEF 1-2-x Distrib ABC DEF GHI 1-2-x I'm getting to .split() all words after "Distrib " and I've to fulfill following conditions: If string[0] is…
Qex
  • 317
  • 1
  • 3
  • 9
3
votes
3 answers

Big-O time complexity for this recursive Fibonacci?

I have a program that prints Fibonacci Series using Recursion. There are better methods for it, but I was asked to use recursion so i had to do it this way. Here is the program: #include #define TERMS 10 long fibo(int); int main(void){ …
3
votes
3 answers

Complexity Analysis in Haskell

positions2 :: (Eq a) => a -> [a] -> [Int] positions2 = f where f aa aas = filter (g aa aas) [0 .. (length aas - 1)] g aa aas it = aa == aas !! it This code is to find out positions of a given element in…
anujuhi01
  • 71
  • 7
3
votes
3 answers

Why does the return statement increase the complexity?

I use SonarQube for a Java project but the complexity calculation is not clear for me. The complexity value is 3 for the following example: public boolean even(int i) { if (i % 2 == 0) { return true; } return false; } According to the…
user3517045
2
votes
2 answers

Running Time Calculation

I am trying to learn time complexities. I have come across a problem that is confusing me. I need help to understand this: my_func takes an array input of size n. It runs three for loops. In the third loop it calls for another function that is O(1)…
2
votes
2 answers

How can I reduce a Cognitive Complexity of its method?

I have an method to convert roman numbers to common decimal. I used here an one for cycle and a lot of "if" conditions. SonarLint in my IDE says me that Cognitive Complexity of this method is 33 while 15 is allowed. How can I reduce this? I do not…
nc_6d
  • 25
  • 7
2
votes
2 answers

C, Time complexity of sigma?

How may I find the time complexity of the following code: (Sorry for adding image, I will re-edit my question once I have access to the laptop) What I have done so far: The first loop iterates n times, the second i times and the third log(i*j)…
user13750697
2
votes
1 answer

Compexity of a list that double its size

I don't understand why the complexity of res = res + res is O(n). In this code res doubles its size in each iteration, thus the complexity of this line is changing with each iteration as follows: 2 + 4 + 8 + ... + n = O(n) I'm confused about why…
1
2
3
12 13