The Big-O notation is used to represent asymptotic upper bounds. It describes relevant time or space complexity of algorithms. Big-O analysis provides a coarse and simplified estimate of a problem difficulty.

learn more… | top users | synonyms

1
vote
2answers
50 views

Understanding θ(f(n)) as defined in the Structure and Interpretation of Computer Programs

I'm having trouble understanding a small passage in The Structure and Interpretation of Computer Programs, and I'm hoping someone can help me interpret it. In the book's introduction to Orders of ...
1
vote
2answers
276 views

O(n^2 * 2^(log n)) == O(n^2)

Is O(n^2 * 2^(log n)) == O(n^2) ? Why I think that this could be the case: In big O, you only take the parts of the term that are most relevant, right? O(n^2 + 3n + 9) == O(n^2). The n^2 has a lot ...
1
vote
1answer
114 views

Does algorithm time complexity O(5) considered as O(1)? [duplicate]

I have someone homework to make and in the instructions it says that we need to implement a function in O(1). Now, does it mean that I can make my function in O(5) or O(2) or whatever?
1
vote
2answers
142 views

Binary Search O(log(n)) or O(n)

I see where most readings online derive that the Big-Oh notation of a Binary Search is O(log(n)), but doesn't this assume a balanced tree? What if the tree is completely unbalanced (i.e. similar to a ...
0
votes
1answer
44 views

How to calculate big O notation according to number width?

I'm trying to understand big O with the bitwise operations. I have 2 functions those are solving the same question from different perspective. num1BitsSecondSolution starts to shift the number right ...
1
vote
2answers
263 views

What is Big O of sqrt(1) + sqrt(2) + … + sqrt(n)? [duplicate]

Given for example this code: for(int i=1;i<n;i++) for(int j=1; j < sqrt(i); j++) foo(); //foo takes constant time can someone explain to me how to calculate the ...
2
votes
4answers
484 views

What is Big-O notation for purely functional languages?

Is it still relevant? Instead of var result = new List<int>(); for (var i = 0; i < prev.Count; ++i) { result.Add(prev[i] * 2); } where the result.Add, prev[i], and * 2 instructions ...
-4
votes
1answer
111 views

BST to AVL in O(n) [closed]

I found in different places on the internet how to turn a Binary Search Tree into an AVL tree in O(nlog(n)). I was wondering how can this be done in O(n) (as the worst case limit). It kinda seems ...
1
vote
1answer
148 views

Complexity of recursive calls

my brain is a little stuck as I am trying to compile an example for my blog. I am presenting an algorithm that draws a number from an array, adds it to a sum and calls itself recursively. func ...
1
vote
1answer
29 views

Expressing complexity based on length of key

I've made a data structure that has insert, search, and delete functions that are base on the number of characters in the key. As an example if it's a number based key (base10), then the complexity ...
5
votes
1answer
93 views

How does cuckoo hashing guarantee O(1) lookups in presence of persistent hash collisions

Most hash table implementations guarantee O(1) average case but O(n) maximum case for lookup (where 'n' is the number of keys in the table). But Cuckoo Hashing is described as O(1) maximum. ...
11
votes
2answers
334 views

Time complexity of 2^sqrt(n)

I am solving an algorithm question and my analysis is that it would run on O(2^sqrt(n)). How big is that? Does it equate to O(2^n)? Is it still non-polynomial time?
2
votes
2answers
194 views

Merge sort and O(n log n) mystery

I read every explanation here but still not convinced. I think mergesort is n * n and I know I am wrong but not sure where. Here is what I think: Suppose we are sorting 8 elements and this is the ...
1
vote
1answer
67 views

How should I express the complexity of two nested loops over different datasets in Big O notation?

I'm more or less teaching myself big O notation, so please forgive me if this is a duplicate of a question which applied to my question without me having the wisdom to realise it. For my own ...
0
votes
2answers
68 views

Big O Notation of an example

My professor gave this example in a lecture: Example: Given an integer N, print out the values 1…N. for (int i=1; i<=N; i=i+1) { System.out.print(i); } The professor said that the loop ...
0
votes
0answers
108 views

Java Multi-threading

I was solving this question in Java where the user enters a partitioned array. The computer then determines what all elements from that array can be used as pivots. (Pivots are the same pivots that ...
5
votes
3answers
170 views

Trying to understand P vs NP vs NP Complete vs NP Hard

I am trying to understand these classifications and why they exist. Is my understanding right? If not, what? P is polynomial complexity, or O(nk) for some non-negative real number k, such as O(1), ...
-1
votes
1answer
65 views

Big O of loop of 0…n with nested loop doing k iterations [duplicate]

My coworkers and I are discussing this code and need a third party to settle our discussion :) Random randNum = new Random(); int[] A = Enumerable.Repeat(0, 1000).Select(i => randNum.Next(0, ...
0
votes
0answers
44 views

Bounded Priority queue with constant time amortized delete min and insert

Given a bounded priority queue (with keys between 1 and k), is there any data structure with amortized constant time for delete min and insert and find min, where the worst case time for these ...
2
votes
1answer
128 views

How to sort a list containing bounded set of values in linear time when length is unknown?

Given a list of integers whose length is unknown, and each of its elements lies between 1 to 1000, how does one sort this list in linear time?
3
votes
1answer
149 views

What is time complexity of update in binary heap?

For a binary heap we have O(log(n)) for insert, O(log(n)) for delete min and heap construction can be done in O(n). In the context of using a binary heap in Djikstra, my exam paper involved an ...
2
votes
1answer
153 views

Time Complexity when Loop Variable Depends upon Outer Loop Variable

What is the time complexity of the following piece of code in worst case? s = 0; for( i = 1; i <= n; ++i ) { for( j = 1; j <= i * i; j++ ) { for( k = 1; k <= j and j % i == 0; ...
1
vote
3answers
254 views

What's the big-O complexity of this recursive algorithm?

I am following a course of Algorithms and Data Structures. Today, my professor said the complexity of the following algorithm is 2^n. I waited till the lesson was over, approached him and told him ...
3
votes
2answers
218 views

Big O Nested For Loop Breakdown

I understand how to get a general picture of the big O of a nested loop, but what would be the operations for each loop in a nested for loop? If we have: for(int i=0; i<n; i++) { for(int ...
1
vote
1answer
59 views

How an add vertex operation could be performed in constant time for a graph represented using adjacency list?

Adding a vertex in a graph that is represented using an adjacency list takes O(1) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency list > add vertex). It is said ...
3
votes
1answer
204 views

why adding a vertex in a graph represented using an adjacency matrix takes O(|v|^2) time complexity?

Adding a vertex in a graph that is represented using an adjacency matrix takes O(|v|^2) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency matrix > add vertex). But ...
5
votes
3answers
762 views

Is O(log n) + O(log n) = O(n)? [duplicate]

We know that binary search takes O(log n) in Big O notation but if we need to run twice an algorithm of O(log n), would it be the same as O(n) in time complexity? For example, if I have a method to ...
5
votes
3answers
4k views

Why is mergesort O(log n)?

Mergesort is a divide and conquer algorithm and is O(log n) because the input is repeatedly halved. But shouldn't it be O(n) because even though the input is halved each loop, each input item needs to ...
-2
votes
2answers
480 views

Difference between O(N^2) and Θ(N^2) [duplicate]

What is the difference between O(N^2) and Θ(N^2)? I know that O is the upper bound and Θ is tight bound. Could someone explain me this concept with an example.
-1
votes
3answers
400 views

What is O(m+n) and O(m*n) in Big O notation? [duplicate]

I understand that O(n) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. An example of this is a for loop: for n in 0.100 puts ...
3
votes
1answer
80 views

Big-O for Immutable Trees

How would you calculate the time and space complexity for a tree algorithm that creates a copy of a tree, but reuses as much of the original tree as possible? For example, A /|\ B C G /|\ D ...
3
votes
1answer
165 views

What is the time complexity of this program?

An algorithm is given on GeeksForGeeks.com for constructing a Binary Search Tree from its preorder traversal. They say that the time complexity for the following code is O(n^2). But in my opinion it ...
1
vote
2answers
684 views

Is the time complexity of a while loop with three pointers different than 3 nested for loops?

This program (written in ruby) finds the largest 3 numbers in an array (without sorting the array). It has a while loop with three pointers. My fist instinct, since there is only one loop is to say ...
19
votes
4answers
3k views

When speaking, how can I say that the time complexity order of an algorithm is O(N log N)?

What term can I use to describe something with O(N log N) complexity? For example: O(1): Constant O(log N): Logarithmic O(N): Linear O(N log N): ?????? O(N2): Quadratic O(N3): Cubic
2
votes
1answer
82 views

Seeds distribution algorithm with complexity better than O(n^3)?

I have included my approach and solution. My solution works fine, however, is unoptimized with O(n^3) complexity An NGO is running seed distribution program. It has limited quantity of varied quality ...
1
vote
2answers
226 views

What is the algorithmic time complexity of this program?

I wrote a simple program in java to create and maintain Dynamic Arrays: public class DynamicArrays { private Integer[] input = new Integer[1]; private Integer length = 0; private Integer ...
-3
votes
4answers
208 views

Time complexity of this loop [duplicate]

Is the time complexity for this loop O(n) or O(log n)? for(i=0;i<n/2;i++){} I am thinking, the time is proportional with the input size.
7
votes
2answers
698 views

Big O equivalence for LINQ select

I'm trying to determine if there is a change in the Big O equivalence of a nested loop when I use a LINQ select instead. public void myFunc(List<Foo> fooList, List<Bar> barList) { ...
1
vote
3answers
385 views

Big O notation of randomness

I was thinking about inefficient algorithms based on randomness and wondered how to categorise them. For instance. Say you wanted to generate all the numbers from 1 to N in a random order but only ...
1
vote
1answer
2k views

Calculate Big-O for nested for loops

I found this nested loop to calculate the Big-O notation. for(i=0;i<n;i++) for(j=0;j<i*i;j++) for(k=0;k<j;k++) I got the time complexity for the algorithm with this polynomial ...
11
votes
9answers
5k views

Big O Question about an algorithm with (n^2 + n) / 2 growth rate

I'm asking this question because I am confused about one aspect regarding big O notation. I am using the book, Data Structures and Abstractions with Java by Frank Carrano. In the chapter on the ...
-2
votes
1answer
148 views

Big O notation for a sub linear algorithm [duplicate]

I have a function for which the complexity raise by the square ten of the exponent of the number. Ex: +-----+----------+ |Input|Complexity| +-----+----------+ |0 | 1 | |10 | 2 | ...
1
vote
2answers
287 views

Big graph traversal with OOP

I'm trying to solve a algorithmic contest's problem. I have a matrix 2000x2000. I want to represent it as graph and traverse it with BFS/DFS. I have time limits on app running (2s). Simple vertices ...
0
votes
2answers
140 views

Time complexity analysis for recurrence relation

I was asked to figure out the time complexity analysis for the following recurrence relation T(n) = 4*T(n-1) + c. Basically, I did a replacement.. T(n-1) = 4 * T(n-2) + c and so on.. T(n) = 4^k T(1) ...
2
votes
1answer
86 views

If I replace N objects with N pointers, is my space complexity still O(N)?

Lets say I get N objects as input, and I need to rearrange them into a different data structure. This means the space complexity of my algorithm will be O(N). But what if I replace the objects with ...
0
votes
2answers
927 views

How does big O notation indicate upper bound on a function? [duplicate]

Suppose we have a function, f(n)=n+10. We say that f(n)∈O(n), meaning O(n) represents the upper bound of the function. It is also true that f(n)∈O(n2) or f(n)∈O(n3) and so on. So how can we say that ...
0
votes
3answers
269 views

Big-O notation for other cases

I was just reading answers to a question Plain English explanation of Big O From that i came to know that Big-O notation is just an "upper bound" of the complexity of an algorithm? But can we apply ...
23
votes
2answers
11k views

Algorithm to merge two sorted arrays with minimum number of comparisons

Given are two sorted arrays a, b of type T with size n and m. I am looking for an algorithm that merges the two arrays into a new array (of maximum size n+m). If you have a cheap comparison ...
0
votes
1answer
81 views

What would be the best sort to use on a something with sorted “chunks”?

Imagine a sorted deck of N cards that has been cut K times by moving X cards from the top to the bottom (X is a different / random amount each time, X is always < N) - what would be the best way to ...
0
votes
1answer
99 views

Handling the process of large-scale lists [closed]

What are the efficient ways to process huge lists (+10 millions), and things to consider while manipulating huge lists. First question, when should I use recursion, and when I shouldn't. In both ...