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

Need help finding the complexity of this algorithm

Hi I need help finding the complexity of this algorithm. Could you please answer the complexity line by line not just the final result? The algorithm is the following one: int algorithm(int x) { int y = 1; while (y <= x-1) { int…
-2
votes
1 answer

How to get the cyclomatic complexity of a ruby function?

I am looking for a function or gem that gives me the cyclomatic complexity of a function. For example, using rubocop, If I write def my_func(foo) foo.details['errors'].each do |attr, message| case attr when 1 then foo.errors.add(:err1,…
-2
votes
1 answer

Which way is faster when stripping part of string in JavaScript

I need to strip part of JWT token and I am courious which one is faster, or less complex internally. Example input string: const input =…
Baterka
  • 3,075
  • 5
  • 31
  • 60
-2
votes
2 answers

What is the time complexity of Python's os.path.exists()?

I have a ton of folders nested inside one another. What is time complexity of Python's os.path.exists() ? Does it change if used with different OS ?
-2
votes
1 answer

Compute the number of Inversions

Let A[1...n] be an array consisting of n different numbers. The pair (i, j) is called an inverse, If i < j and A [i] > A [j]. Example: A := (2, 3, 8, 6, 1) => A has 5 inverses. Task: Write program to find the number of inverses of the array A…
-2
votes
2 answers

Algorithm Complexity vs Running Time

I have an algorithm used for signal quantization. For the algorithm I have an equation to calculate its complexity with different values of parameters. This algorithm is implemented in C. Sometimes according to the equation I have less complexity…
Chamran Ashour
  • 441
  • 1
  • 4
  • 6
-2
votes
2 answers

complexity of simple algorithm

I have the following algorithm but I dont know its' complexity. Could someone help me? Input size is n. int x = n; while (x > 0) { System.out.println("Value is" + x); x = x/5; } Thanks a lot!
idelara
  • 1,786
  • 4
  • 24
  • 48
-2
votes
2 answers

Time complexity - recursive call

I am trying to understand how to compute the time complexity of an algorithm . I have this piece of code: This is the whole method: public void solve(int i) { if(i < 2) { return; } solve(i-1); //recursive call int x =…
-3
votes
1 answer

Is O(n^log(n)) bigger than O(n!)

n is a number between 1 and +infinity and this is to know the complexity of an algorithm I need to see if n^log(n) is bigger than n!
-3
votes
1 answer

Mathematical derivation of O(n^3) complexity for general three nested loops

Time complexity of nested for-loop goes into the mathematical derivation through summation of two loops O(n2) complexity. I tried an exercise to derive how i can get O(n3) for the following examples of three nested loops. Simple three nested loops. …
Saad
  • 915
  • 9
  • 19
-3
votes
2 answers

Sorting an Array with duplicates using Insertion sort

package com.sort; public class ArraySel { private Long[] a; private int nElems; public ArraySel(int max) { a = new Long[max]; nElems = 0; } public void insert(long max) { a[nElems] = max; …
akki_java
  • 605
  • 7
  • 17
1 2 3
12
13