Skip to main content
Filter by
Sorted by
Tagged with
-5 votes
1 answer
77 views

Say I have an algorithm that runs in O(N*M + N + M). Say that although M can vary, it can only be between 1-20. For asymptotic complexity is M treated as a constant? Because you can't really take the ...
user31685420's user avatar
4 votes
2 answers
273 views

int k = 0; for (int a = n; a >= 1; a /= 2) for (int b = a; b >= 1; b--) k++; cout << k; I would say that the answer is O(n), but the book where I have found the exercise says that ...
Andrei Morgovan's user avatar
0 votes
1 answer
103 views

What is the time cost (asymptotically) of the following method?: void fillList(int i) { list = new int[i]; } I have been told that it takes O(1) time because no initialization is done and the ...
Anselmo GPP's user avatar
-2 votes
1 answer
124 views

I have an algorithm that is implemented by the following state table for a Turing machine: 𝑞1 𝑞2 𝑞3 0 0R 𝑞1 1L 𝑞3 0L 𝑞3 1 1R 𝑞1 0L 𝑞2 1L 𝑞3 _ _L 𝑞2 1S 𝑞0 _3 𝑞0 I want to determine the ...
Muhab Joumaa's user avatar
4 votes
1 answer
152 views

I am trying to solve the following algorithmic problem: Every day, Bob goes to work and does one of 26 possible tasks. The tasks are coded with the letters of the English alphabet from a to z. ...
clearcut3000's user avatar
2 votes
0 answers
113 views

Let’s say we have a list of intervals, each of which has a cost associated with it. Assume that there is always at least one interval active. The solution would be a timeline of non overlapping ...
Isak's user avatar
  • 95
0 votes
0 answers
63 views

I am trying to lower the complexity of my code and I use Scrutinizer to measure those values. In my code, most of the complexity is due to validations, so how can I improve them? class gestionRegister:...
Diego Marin's user avatar
0 votes
2 answers
78 views

I am writing unit tests in JUnit 5 for a Java codebase, though I'm happy to take examples in any language. I have the ability to count the exact number of times certain operations occur. For the sake ...
Stephen Ware's user avatar
1 vote
2 answers
242 views

I'm new to multithreading algorithms and I'm trying do recode cumulative sum function to get a better complexity than O(n). Have you any hint? Or we can't get better than O(n)? I tried to use divide ...
Mutmut's user avatar
  • 13
2 votes
2 answers
80 views

I tried to solve leetcode problem Select Cells in Grid With Maximum Score. You are given a 2D matrix grid consisting of positive integers. You have to select one or more cells from the matrix such ...
Harry 's user avatar
  • 21
-4 votes
1 answer
107 views

Lets say I have a certain number of schools and a certain number of students. For each student i want to compute a new grade from their old grade using a random coefficient. I use as much arrays as I ...
user642308's user avatar
0 votes
0 answers
56 views

Below is a code that makes a network where each node of the network is a Stuart-Landau oscillator. The equations of evolution are coupled and also depend on it's neighbors. The code runs 10^6 ...
Zenitsu's user avatar
1 vote
2 answers
118 views

Need help on how to calculate this time complexity int func(int n) { int a = 0; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= n - i; ++j) { for (int k = 0; k &...
Guy Cohen's user avatar
-1 votes
1 answer
156 views

int func2(int arr[], int n) { int i = 0, j, counter = 0; MergeSort(arr, n / 6); // 1 while (i < n / 6) // 2 { for (j = 6; j < n / 6; j *= j) // 3 counter++; ...
python_1239's user avatar
0 votes
1 answer
79 views

For example: #include <iostream> using namespace std; int main() { int n, s = 0, i, j, k; cin >> n; for (i = 1; i <= n * n; i++) { for (j = 1; j <= i / 2; j++) ...
Leon's user avatar
  • 3
0 votes
1 answer
58 views

I'm doing a comparison between brute force search and my custom search approach. A problem arose in estimating the complexity of a brute-force search. As part of the search, I need to check whether ...
Stanislav Danylenko's user avatar
1 vote
0 answers
61 views

This is in the context of graph algorithms, so I'll refer to V as the set of vertices in the graph and E as the set of edges in the graph (i.e., the input is a graph G = (V, E)). Let's say a graph ...
Hugh Mann's user avatar
0 votes
1 answer
311 views

I tried to find out how to solve recurrences using substitution method, but I don't understand: how is the base case chosen when the base case is not given explicitly? I have two problems: T(n) = 2T(...
poilouyh's user avatar
1 vote
0 answers
248 views

Let's look at the complexities of the <preprocess, query, update an element> operations. Let's denote n the size of the initial array and q the number of queries. Sparse table <O(nlogn) , O(...
FluidMechanics Potential Flows's user avatar
0 votes
1 answer
61 views

i was given an assignment to find an algorithm that takes an array A such that for every x<y we have the first appearance of x coming before the first appearance of y and sorts it in average time ...
Nadav Avnon's user avatar
-1 votes
1 answer
38 views

I am trying to solve LeetCode problem 143. Reorder List: You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln − 1 → Ln Reorder the list to be on the ...
Rat's user avatar
  • 3
1 vote
1 answer
35 views

An insert into a hash table has a worst case complexity of O(n). But when creating a new hash table and inserting n elements, as far as I understand this would result in n insertions into a growing ...
mxcx's user avatar
  • 139
0 votes
0 answers
53 views

I am confused about the time complexity of this algorithm because I am thinking it could be something like T(n) = 3T(n/2) ... but since the array has a size of nxm instead of nxn and I am using ...
Leah M's user avatar
  • 21
1 vote
1 answer
77 views

How do we find the time complexity of below program? For the below program should the time complexity be O(N) or O(N*M) or O(N*M*M)? Take-1: O(N) to scan N elements in the input array Take-2: O(N*M) ...
Matthew's user avatar
  • 407
0 votes
2 answers
121 views

Static void doIt (int n ) { int i; // 1 operations int j; ← (2 x n) // 1 operations while loop (j > 0) { // n operations I; ← n // (n+1) operations ...
struggling-cs-student's user avatar

1
2 3 4 5
94