Skip to main content
Filter by
Sorted by
Tagged with
-5 votes
1 answer
86 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
2 votes
3 answers
119 views

Let's say I have this pseudocode: int n = 100 for (int i = 1; i<=n; i++) System.out.println("Hello!"); for (int j = 1; j<=n; j++) System.out.println("World!!!"); end ...
ALFIAN BIN ABDUL HALIN  FSKTM's user avatar
4 votes
2 answers
280 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
1 vote
2 answers
213 views

Suppose we want to generate a 5-digit unique student ID i.e. there are N = 100,000 possible values (from 00000 to 99999). What is the big O of the algorithm below? - while True: - Generate a random ...
Paolo Tormon's user avatar
0 votes
1 answer
105 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
-1 votes
1 answer
42 views

Is the complexity defined by the big-O notation e.g., n! is always more complex than n^3, regardless of the value of n? What if I know n = 3? Would I be able to say that in this case O(n!) is less ...
gorilla's user avatar
  • 47
-2 votes
1 answer
146 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
1 vote
1 answer
90 views

Reading up on backtracking led me to a page on geeksforgeeks.org about solutions to the n-queens problem. The first solution is introduced as the "naive approach" that generates all possible ...
retpoline's user avatar
4 votes
1 answer
155 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
0 votes
0 answers
46 views

I have two finite sets of strings S_1, S_2 that are described by DFAs (e.g. these sets are regular languages, but I want to emphasize the fact that they are finite of known maximum length). I need to ...
zugzwang's user avatar
2 votes
0 answers
115 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
1 vote
1 answer
128 views

Isn't every function is ω(0)? From my understanding, ω (little omega) notation is used as a strict lower bound for any function. Since no function can run in less than 0 "time" then ω(0) ...
Vricken's user avatar
  • 117
0 votes
0 answers
73 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
-1 votes
1 answer
158 views

I am working on a vehicle tracking application, and im trying to get the moving animation of the car smooth, with no "jumps" and a continous movement of the map with the current location. ...
Ravid Ofek'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
-4 votes
1 answer
232 views

The following is a Leetcode problem: 473. Matchsticks to Square (https://leetcode.com/problems/matchsticks-to-square/description/) Problem Statement You have an array, matchsticks, of size n, with ...
monre's user avatar
  • 135
1 vote
2 answers
257 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
-1 votes
1 answer
97 views

I would like to know how to properly determinate the complexity of this function : let rec fact n = match n with | 0 -> 1 | n -> n * fact (n - 1) let biggest_factorial_below n = let i = ...
RyzenDev's user avatar
2 votes
2 answers
89 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
1 vote
1 answer
63 views

This is a homework problem I have. I could not find whether it was against the rules or not to post such a question. I cannot figure this one out. I would appreciate help in understanding why the ...
user avatar
-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
-2 votes
1 answer
149 views

I was studying Time Complexities in my DSA lecture when this doubt popped in my mind. So firstly, is O(nlog(n)) = O(log(n^n))? If yes, what type of Time Complexity does the O(log(n^n)) belong to? Is ...
Xploitashan's user avatar
0 votes
0 answers
60 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
1 answer
66 views

Assume we have a directed bipartite graph G with two partitions, A and B. All the edges are assumed to start from A and end in B . Assume that every vertex has at least one adjacent edge. I want to ...
Abc's user avatar
  • 11
1 vote
2 answers
126 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
4 votes
1 answer
303 views

I've implemented two versions of radix sort (the version that allows sorting integers whose values go up to n² where n is the size of the list to sort) in Python for benchmarking against the standard ...
FluidMechanics Potential Flows's user avatar
-1 votes
1 answer
160 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
1 vote
2 answers
87 views

I am trying to understnad if the following codes have the same complexity O(n)?: for(int i=0;i<n;i++) for(int i=0;i<100000;i++) i would be happy to hear an explanation too, thank you ! I think ...
Ryan's user avatar
  • 23
0 votes
1 answer
84 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
0 answers
95 views

I've read some articles about algorithms analysis and sometimes they seem to use two terms interchangeably and sometimes there seems to be a subtle difference. So I'd like to know about it explicitly, ...
Rafael's user avatar
  • 63
0 votes
1 answer
64 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
1 answer
85 views

This is supposed to be a very simple question. In the Prologue of Christopher Moore's book "The Nature of Computation" (2011), page 3, the number of possible routes of the Königsberg problem ...
FJDU's user avatar
  • 1,483
1 vote
0 answers
65 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
0 answers
64 views

I am a math student and I have been asked to help grade answer sheets for an Algorithms course as one of my professors is unwell. While I am quite familiar with combinatorial algorithms, I am not well ...
Umesh Shankar's user avatar
0 votes
1 answer
319 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
0 votes
3 answers
201 views

I attempted to solve the problem at this HackerRank link (https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true) Given a square matrix, calculate the absolute difference ...
Mário Alfredo Jorge's user avatar
1 vote
0 answers
255 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
2 answers
165 views

Input: Array of integers A[0..n – 1] Output: Smallest difference between two elements of a dmin array dmin = ∞ for i = 0 to n − 1 do for j = 0 to n − 1 do if i != j &&|A[i] − A[j]| &...
SophiaAkr'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
0 votes
1 answer
97 views

I want to be able to measure any code snippet time complexity. Is there a general rule or step by step approach to measure any big o (besides dominant term, removing constants and factors)? What math ...
Abraam's user avatar
  • 25
-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
59 views

I started reading the Competitive Programmers Handbook, and on page 20 the author writes about varying algorithmic complexity classes. When covering √𝑛, he writes: O(√𝑛) A square root algorithm is ...
Qamber's user avatar
  • 11
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
34 views

I recently stumbled upon an optimization problem while working on structural analysis. While I'm confident in my MATLAB skills as an aerospace engineer, I must admit my theoretical knowledge in ...
user23509645's user avatar
0 votes
0 answers
58 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
4 votes
1 answer
132 views

def permutation(str): #str = string input if len(str) == 0: return [""] result = [] for i, char in enumerate(str): for p in permutation(str[:i] + str[i + 1 :]...
Alvalen Shafel's user avatar
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
  • 417
-4 votes
1 answer
289 views

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 ...
impossibru's user avatar
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
0 votes
1 answer
75 views

I'm tryng to implement Sosic and Gu algorithm for the n-queens problem-which presents a phase of initialization called initial_search(). The algorithm starts by assigning queens to random positions on ...
Tacce's user avatar
  • 3

1
2 3 4 5
94