193 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
290
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 ...
-1
votes
1
answer
181
views
Time Complexity of "in" keyword in python when using a list? Leetcode
I read a little bit everywhere that the "in" operator have a time complexity of O(n), yet I used it in a code and idk why but it's acting as if it have the time complexity O(1)
So I was ...
-4
votes
1
answer
283
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 ...
0
votes
1
answer
125
views
Can someone give an Optimized approach? [closed]
Find distinct triplet (i,j,k) such that i<j<k and sum of the arr[i]+arr[j]+arr[k] is divisible by d?
If arr = [3, 3, 4, 7, 8] and d = 5 it should give count as 3
triplet with indices (1,2,3) 3+...
1
vote
1
answer
116
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, ...
0
votes
1
answer
112
views
What is the number of operation for K pair quick find algorithm?
For my code which is an implementation of the quick find algorithm i generally consider my code for understanding theoretical questions
#include <stdio.h>
#define N 10000
main() {
int i, t,...
5
votes
1
answer
265
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 ...
0
votes
2
answers
132
views
Reduce cognitive complexity when mapping
if(obj.getAttribute() != null) {
newobject.setAttribute(obj.getAttribute());
}
if(obj.getAttribute() != null) {
newobject.setAttribute(obj.getAttribute());
}
if(obj.getAttribute() != ...
-2
votes
1
answer
285
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|
...
-1
votes
1
answer
129
views
What is the time-complexity of this program (c++)
Code:
#include <iostream>
#include <vector>
template<typename T>
std::vector<T> flatten(std::vector<std::vector<T>> const &vec)
{
std::vector<T> ...
0
votes
0
answers
65
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
1
answer
31
views
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 ...
0
votes
0
answers
73
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(...
1
vote
0
answers
72
views
How do I reduce the cyclomatic complexity in this code?
I added the getCValue method to reduce the cyclomatic complexity, but the cyclomatic complexity still persists, how can I reduce it? Can I change this code using Regex, if I can how? Please help me.
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 ...