193 questions
1
vote
1
answer
300
views
Can someone determine time complexity of this LeetCode solution I made?
I wrote a solution to the problem linked below but I'm not sure about its time complexity. I was thinking it was quadratic but it passed within 0 ms when I submitted, so it might be linear idk. I ...
-4
votes
1
answer
285
views
how do i find the time complexity (big O) of this triple loop?
for (int i = 0; i < n^2; i++) {
for (int j = 1; j < i; j = 2j) {
for (int k = 0; k < j; k++) {
System.out.println("x");
}
}
}
My thoughts are that the outer loop ...
1
vote
1
answer
120
views
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<MyModel> {
func lands(in council: Council, ...
5
votes
1
answer
273
views
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 ...
-2
votes
1
answer
300
views
How to get the cyclomatic complexity of a ruby function? [closed]
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|
...
0
votes
0
answers
67
views
Java, calculating complexity
I am trying to calculate complexity of a recursion method inside another methos in a simple while loop.
I dont know how to asnwer this question, I think To just apply the answer O(N*Y) while Y stands ...
0
votes
0
answers
75
views
Order of complexity of a matrix (matlab)
I need some help answering this question : How do I find the complexity of the matrix B and f knowing that I have this code :
d = 123456;
randn('state',d); rand('state',d);
n = 1000; A = diag(1+rand(...
2
votes
2
answers
307
views
Merge similar objects together based on object elements is O(n²). How to make it simpler? [closed]
Problem Description
We have a vector<A> v containing for 4 objects. Each object has the following members x, y, z and w. Two objects are considered equal if the have the same x and y. In that ...
1
vote
1
answer
130
views
Confusion regarding while loop in for loop for time complexity
I'm learning about time complexity and I understand the gist of it, but there's one thing that's really confusing me, it's about understanding the time complexity of a while loop in a for loop.
This ...
1
vote
0
answers
48
views
Code Complexity Misunderstanding of Single Element in a Sorted Array
The problem which is on LeetCode says that
You are given a sorted array consisting of only integers where every
element appears exactly twice, except for one element which appears
exactly once.
...
0
votes
0
answers
46
views
Proving algorithm complexity
Hello I have a binary search function and I want to prove that it has Logarithmic complexity.
I have no idea how to prove this and would really use some help
Here are my execution times for the ...
0
votes
3
answers
716
views
How can I calculate the complexity of a program like this
So I have been studying the complexity of algorithms, but this one I can't uderstand.
If I use a global variable to check how many times the function is called it will calculate the number 11 then ...
1
vote
0
answers
120
views
Runtime of the recursive algorithm?
I am learning algorithm complexities. So far it has been an interesting ride. There is so much going behind the scenes that I need to understand. I find it difficult to understand complexity in ...
0
votes
1
answer
121
views
tree traversal runtime and space analysis general approach
I am currently on 94. Binary Tree Traversal on leetcode and I am not sure how to analyze the run time and space complexity of the question. In my opinion, the time complexity for the question seems to ...
0
votes
1
answer
40
views
How to handle a wide variety of object types for the same data
I am building an application which uses a lot of vectors and for which I am using a lot of third party and system assemblies. The result of this is that I have four ways to to represent 3d double ...
7
votes
1
answer
376
views
Sonar integration with lizard to track code complexity failing in android studio
I am trying to integrate lizard to track the code complexity of an android app on sonarqube. The command used to get the complexity report from lizard is:
lizard src/main -x"./test/*" -x&...
0
votes
1
answer
613
views
Concise if else in Kotlin
Is there a way to remove this if else block inside snackbar by replacing it with lambda or infix or anything to make it without +2 nesting in cognitive complexity
else {
snackBarBuilder(
...
0
votes
1
answer
150
views
Asymptotic complexity in python for O-Upper
I'm studying the complexity of functions in python, and I have this two there Im not sure, one because I think it's infinite loop and second is the not in method build in on python:
1- The function f1 ...
0
votes
0
answers
27
views
What will be time and complexity of given code
F(i, j) represents the maximum value the user
can collect from i'th coin to j'th coin.
F(i, j) = Max(Vi + min(F(i+2, j), F(i+1, j-1) ),
Vj + min(F(i+1, j-1), F(i, j-2) ))
As user wants ...
1
vote
0
answers
216
views
What is the time complexity of BitArray initilized to 0?
when creating a BitArray and initializing all of its value to 0 (via constructor, new BitArray(size, false);) what is the time complexity of such operation? It's not in the docs about collections.
...
0
votes
1
answer
153
views
what is the code-complexity of n-x series?
If you had an algorithm with a loop that executed n steps the first time through,
then n − 2 the second time, n − 4 the next time, and kept repeating until the last time through the loop it executed 2 ...
0
votes
1
answer
380
views
Determining the exact number of executions of an algorithm
I have algorithm such as:
for(int i=1; i<=n; i++)
for(int j=1; j<=2*n; j=j+2)
for(int k=i; k<=j; k++)
instr;
I need to find a formula that will determine how many times the &...
1
vote
2
answers
776
views
Time complexity of a recursive function having two nested for loop inside it
function recursion(n){
if n==0
return
for(let i=0; i < n;i++){
for(let j=0; j< n; j++){
console.log('*');
}
}
recursion(n-1);
}
recursion(100);
What is ...
0
votes
2
answers
391
views
Time Complexity and Space Complexity of the Python Code
Can someone please help me with the time and space complexity of this code snippet? Please refer to the leetcode question- Word break ii.Given a non-empty string s and a dictionary wordDict containing ...
1
vote
2
answers
129
views
What's complexity of this algorithm?
I'm learning how to find algorithm complexity and I can't figure out what's the complexity of this algorithm. Could someone explain to me how to get the answer?
void algorithm(int a, int b) {
...