time-complexity Questions

2

Solved

From cplusplus.com std::sort complexity is defined: Complexity Approximately N*logN comparisons on average (where N is last-first). In the worst case, up to N2, depending on specific sorting...
Sarcocarp asked 28/8, 2011 at 13:27

9

Solved

Let's say we have a problem where a certain algorithm, let's call it algorithm_1, solves it in time complexity of O(n^2) and another algorithm, let's call it algorithm_2, solves it in time co...
Ceratodus asked 12/1, 2023 at 22:16

2

Solved

I'm now learning Kademlia network by reading the classical paper Kademlia: A Peer-to-peer Information System Based on the XOR Metric. I want to understand the complexity of its operation but still ...
Bolger asked 12/3, 2015 at 8:13

5

How can we prove that the update and query operations on a segment tree (http://letuskode.blogspot.in/2013/01/segtrees.html) (not to be confused with an interval tree) are O(log n)? I thought of a...
Otherworldly asked 28/11, 2014 at 9:1

10

Solved

I need to calculate the time complexity of the following code: for (i = 1; i <= n; i++) { for(j = 1; j <= i; j++) { // Some code } } Is it O(n^2)?
Harr asked 9/2, 2009 at 0:5

4

Solved

I know we can use DFS for maze exploration. But I think we can also use BFS for maze exploration. I'm little bit confused here because most of the books and articles that I've read had used DFS for...

3

Solved

Can someone explain me when it comes to binary search we say the running time complexity is O(log n)? I searched it in Google and got the below, "The number of times that you can halve the searc...
Gothart asked 1/6, 2011 at 5:58

1

Solved

In std::holds_alternative and std::get_if documentation, it does not say what's the complexity requirements of the operations. Are the two functions always O(1), or it's linear in terms of number o...
Egret asked 23/12, 2022 at 7:44

4

Solved

I was going through this question to calculate time complexity. int fun(int n) { int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count += 1; return count; } ...
Claudy asked 12/11, 2015 at 16:54

6

Solved

I have an array like this students = [{name: 'Abbey', age: 25}, {name: 'Brian', age: 45}, {name: 'Colin', age: 25}, {name: 'Dan', age: 78}] and I want the output to be; uniqueAges = [45, 78] ...
Sheridan asked 14/3, 2018 at 3:46

18

Solved

For example: input: A = [ 6 4 3 -5 0 2 -7 1 ] output: 5 Since 5 is the smallest positive integer that does not occur in the array. I have written two solutions to that problem. The first one i...
Guinevere asked 11/3, 2018 at 19:15

4

Solved

How is the bottom up approach of heap construction of the order O(n) ? Anany Levitin says in his book that this is more efficient compared to top down approach which is of order O(log n). Why?
Nitrogenous asked 25/3, 2016 at 19:33

3

Solved

I have some difficulties in understanding the time complexity analysis for one solution for the Happy Number Question from Leet code, for my doubts on complexity analysis, I marked them in bold and...
Unqualified asked 21/11, 2019 at 14:49

7

Solved

This is a follow up to a similar question which asked the best way to write for item in somelist: if determine(item): code_to_remove_item and it seems the consensus was on something like some...
Laryngotomy asked 21/4, 2011 at 14:59

7

Solved

There is an array related problem, the requirement is that time complexity is O(n) and space complexity is O(1). If I use Arrays.sort(arr), and use a for loop to one pass loop, for example: publi...
Jugum asked 21/3, 2014 at 23:57

3

Solved

I am supposed to solve this problem in as low time complexity as possible, but let me be more specific. You are given a sorted array of integers that contains duplicates. Unique quadruple is a set ...
Quicken asked 30/10, 2022 at 14:26

10

Solved

I have gone through Google and Stack Overflow search, but nowhere I was able to find a clear and straightforward explanation for how to calculate time complexity. What do I know already? Say for co...
Charitycharivari asked 14/6, 2012 at 11:21

4

Solved

Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] My Ite...
Synthiasyntonic asked 13/1, 2017 at 5:11

2

I have to calculate the cost of this algorithm. I was thinking about an exponential cost. I tried the recurrence relation. 4*T(n/4) + c*n and at the end it's ((4^n) - 1)/3. Is that correct? Are t...
Gomar asked 2/7, 2018 at 9:50

2

Solved

I recently attended an interview and they asked me to solve the below problem by using O(n) time complexity. (Hackerranker) Problem: Given an integer array and there will be l integer and r integer...
Douma asked 30/9, 2022 at 16:23

7

Solved

I am trying to learn analysis of algorithms and I am stuck with relation between asymptotic notation(big O...) and cases(best, worst and average). I learn that the Big O notation defines an upper ...

32

Solved

I am learning about Big O Notation running times and amortized times. I understand the notion of O(n) linear time, meaning that the size of the input affects the growth of the algorithm proportiona...
Gingersnap asked 21/2, 2010 at 20:5

2

Solved

I've noticed the table of the time complexity of set operations on the python official website. But i just wanna ask what's the time complexity of converting a list to a set, for instance, l = [1,...
Amphiarthrosis asked 6/1, 2016 at 20:28

8

Solved

As per my understanding, I have calculated time complexity of Dijkstra Algorithm as big-O notation using adjacency list given below. It didn't come out as it was supposed to and that led me to unde...
Wooster asked 24/10, 2014 at 12:24

9

Why is the time complexity of node deletion in doubly linked lists (O(1)) faster than node deletion in singly linked lists (O(n))?

© 2022 - 2024 — McMap. All rights reserved.