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
2
votes
0 answers

C# Linq SelectMany complexity

What is the complexityclass of a Linq Queryable.SelectMany. I'm looking for Big O notation to predict runtime efficiency. I checked Microsoft Docs and several other sources. In this StackOverflow complexity is noted as O(N^2) what doesn't make sense…
Richard Wieditz
  • 406
  • 1
  • 4
  • 14
2
votes
1 answer

Can the minimum time to schedule tasks be found without brute force?

If I have a list of integers representing the time it takes for a task to be completed and I have x workers that can only work on one task until the time it takes to complete is up, can I find the minimum time it could possibly take in a best case…
2
votes
0 answers

How to Count Number of Line of per Class and Method in Radon?

I'm using python radon to audit my developer's coding quality. However, I would like to count number of line for each class, method, and function. The only options available are $ radon cc test.py Cyclomatic Complexity gives me every function…
Houy Narun
  • 1,557
  • 5
  • 37
  • 86
2
votes
0 answers

How can I measure the computational complexity of my Convolutional Neural Network Model?

I have to evaluate my CNN model for Semantic Segmentation (when predicting) in terms of computational complexity, memory use and processing time. I work with Python (Keras). Is there a way to count the number of operations performed in each layer or…
2
votes
1 answer

How to calculate complexity of non-standard day to day algorithms

Hello StackOverflow community! I had this question in my mind from so many days and finally have decided to get it sorted out. So, given a algorithm or say a function which implements some non-standard algorithm in your daily coding activity, how do…
2
votes
1 answer

Finding the complexity - Swift

What would the complexity (Big-O notation) for the following function: func sortList(_ thresholdValue: Int) -> [Int] { var currentValue = thresholdValue //Values is an array of integers - [Int] var valArr = values.sorted { $0 > $1 }…
DesperateLearner
  • 1,115
  • 3
  • 19
  • 45
2
votes
2 answers

Given a source and a final array, find the number of hops to generate final from the source in less than quadratic time complexity

Suppose you have an array of integers (for eg. [1 5 3 4 6]). The elements are rearranged according to the following rule. Every element can hop forward (towards left) and slide the elements in those indices over which it hopped. The process starts…
2
votes
3 answers

Simple Algorithm complexity

I have an algorithm and I need help finding the complexity of it (tightest possible upper bound) for(int i = 0; i < n/2; i++) for(int j = 0; j < n/4; j++) for(int k = 0; k < n; k++) x++; My analysis is that if n would not be…
idelara
  • 1,786
  • 4
  • 24
  • 48
2
votes
2 answers

How to break complex query into different methods to achieve less code complexity

I have a complex query which needs to be broken into different methods in order to meet NFR code complexity criteria. I know this is bad just to meet criteria it is desired, but can this query can be broken into smaller chunks? var query = (from a1…
VSharma
  • 348
  • 2
  • 12
2
votes
1 answer

Extract a snippet of code from Ruby-based source file

I've been playing with flog lately, its a pretty good tool to generate reports on code complexity for ruby applications. As a result of running flog on a project codebase you get an output that looks similar to this: 1272.3: flog total 7.3:…
Dan Sosedoff
  • 2,869
  • 5
  • 28
  • 34
2
votes
1 answer

finding the complexity of insertion to avl tree

If I have an empty avl tree and I want to insert a set of ordered numbers (1, 2, ... k), why the complexity is O(k). thank you
Rawhi
  • 6,155
  • 8
  • 36
  • 57
2
votes
1 answer

What's the meaning of "complexity" - how do I calculate it?

As the title say: I don't know the meaning of "complexity" When I visit a web page of sonar result I would very much want to know how to calculate it.
Lheart
  • 59
  • 4
2
votes
2 answers

Code Complexity in 3 array case

You are given with three sorted arrays ( in ascending order), you are required to find a triplet ( one element from each array) such that distance is minimum. Distance is defined like this : If a[i], b[j] and c[k] are three elements then distance =…
tcp
  • 289
  • 3
  • 5
  • 15
1
vote
1 answer

Swift enumerators: how is it implemented for empty collection?

I'm implementing a few custom enumerators for my data model, e.g. struct Land { // … let council: Council let size: Int } extension Collection { func lands(in council: Council, above size: Int) -> [Land] { guard isEmpty ==…
Heuristic
  • 5,087
  • 9
  • 54
  • 94
1
vote
1 answer

Complexity of an example with only one for loop

I'm getting started with complexity and I wanted to know why the example given below is O(n^2) and not O(n), would you guys help me? I need it fast for an exam. l1 = [] for e in range(0, n): if e in range(n, 2n): l1.append(e**3)
1 2
3
12 13