Questions tagged [asymptotic-complexity]

Asymptotic complexity is an approximation of the edge case performance of an algorithm used to determine best and worst case scenarios.

796 questions
6
votes
2 answers

Big-O running time of various search algorithms

The method hasTwoTrueValues return true if at least two values in an array of boolean are true. Provide the Big-O running time for all three implementations proposed. // Version 1 public boolean hasTwoTrueValues(boolean[] arr) { int count = 0; …
5
votes
3 answers

Give an asymptotic upper bound on the height of an n-node binary search tree in which the average depth of a node is Θ(lg n)

Recently, I'm trying to solve all the exercises in CLRS. but there are some of them i can't figure out. Here is one of them, from CLRS exercise 12.4-2: Describe a binary search tree on n nodes such that the average depth of a node in the tree is…
5
votes
3 answers

How can I reduce big O complexity of two for loops

The function must return the count of pairs of numbers in the array songs (integer array consisting of lengths of songs in seconds) such that the pairs formed add up to whole minutes. long playlist(int songs_count, int *songs) { int i, j, k =…
Henodi
  • 75
  • 1
  • 1
  • 10
5
votes
1 answer

What are the asymptotic upper and lower bounds for T(n) = 2T(n/2) + n lg lg n?

The recurrence relation T(n) = 2T(n/2) + n lg lg n (where lg is logarithm to base 2) can be solved using the master theorem but I am not very sure about the answer. I have found my answer but am not mentioning it here in order to prevent…
Programmer
  • 6,565
  • 25
  • 78
  • 125
5
votes
2 answers

How the time complexity of gcd is Θ(logn)?

I was solving a time-complexity question on Interview Bit as given in the below image. The answer given is Θ(theta)(logn) and I am not able to grasp how the logn term arrive here in the time complexity of this program. Can someone please explain…
5
votes
1 answer

Algorithmic complexity converting CSC to CSR

I was wondering what the algorithmic complexity of a conversion from CSC (compressed sparse column) to CSR (compressed sparse row) is? Say I have a CSC m x m-matrix A = csc(m,m) with n non-zero elements a CSR m x m-matrix B = csr(m,m) with n…
Armen Avetisyan
  • 1,140
  • 10
  • 29
5
votes
4 answers

Worst case vs O(n)

Is there a difference between statement "Worst case running time of an Algorithm A" and "Running time of an Algorithm A is O(n)"? What I think "there is no difference" because, worst case is the peak running time that the function can take, O(n)…
rda3mon
  • 1,709
  • 4
  • 25
  • 37
5
votes
1 answer

Finding the average case complexity for an algorithm?

I'm very lost on finding average case complexity, just pulling a random problem...like. For a sentinel sequential search, find the average case if the probability is 0 <= p <= 1. I get the worst case would be O(n+1) as there would be n elements…
Carson Wood
  • 1,174
  • 3
  • 14
  • 23
5
votes
1 answer

Confused on how to find c and k for big O notation if f(x) = x^2+2x+1

I am studying big O notation from this book. The deffinition of big O notation is: We say that f (x) is O(g(x)) if there are constants C and k such that |f (x)| ≤ C|g(x)| whenever x > k. Now here is the first example: EXAMPLE 1 Show that f (x) =…
lightning_missile
  • 2,821
  • 5
  • 30
  • 58
5
votes
2 answers

Asymptotic complexity of logarithmic functions

I know that in terms of complexity, O(logn) is faster than O(n), which is faster than O(nlogn), which is faster than O(n2). But what about O(n2) and O(n2log), or O(n2.001) and O(n2log): T1(n)=n^2 + n^2logn What is the big Oh and omega of this…
Joseph D
  • 115
  • 7
5
votes
1 answer

What is the complexity of calling of dict.keys() in Python 3?

What's the asymptotic complexity of dict.keys() in python? I found this website but it does not have the answer. I am using Python 3, but I guess this is not version specific.
5
votes
1 answer

Radix sort explanation

Based on this radix sort article http://www.geeksforgeeks.org/radix-sort/ I'm struggling to understand what is being explained in terms of the time complexity of certain methods in the sort. From the link: Let there be d digits in input integers.…
maregor
  • 777
  • 9
  • 32
5
votes
2 answers

What is the complexity of the code to find word in a set of cubes

I have solved the program here. Previously I thought complexity was O(n!) where n were characters in the word. But today I feel it is wrong. It should be (6)^(characters in the word) where 6 is the sides in the cube. Making it more generic, assuming…
5
votes
3 answers

Do log bases matter in Big O domination?

Given two functions: f(n)=O(log2n) and g(n)=O(log10n) Does one of these dominate the other?
Deekor
  • 9,144
  • 16
  • 69
  • 121
5
votes
4 answers

HRW rendezvous hashing in log time?

The Wikipedia page for Rendezvous hashing (Highest Random Weight "HRW") makes the following claim: While it might first appear that the HRW algorithm runs in O(n) time, this is not the case. The sites can be organized hierarchically, and HRW…