Questions tagged [big-o]

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.

Filter by
Sorted by
Tagged with
-4
votes
1answer
36 views

What is the worst case Time Complexity for only the Divide Portion of the Merge Sort Algorithm?

Please, consider the below merge sort algorithm. Here we start with a divide portion which splits the array into halves and we do recursive operation on each half separately. I have ignored the merge ...
51
votes
4answers
65k 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), O(...
1
vote
3answers
219 views

Are there any programs or IDEs that calculate Big-O notation on functions? Is this something that is possible to program into an IDE?

Is there anything that can calculate the Big-O notation of a function? While learning about Big-O, it is implied that it is pretty trivial to do in your head once you know the basic rules, however if ...
5
votes
3answers
11k 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 ...
32
votes
2answers
11k views

What is O(…) and how do I calculate it?

Help! I have a question where I need to analyze the Big-O of an algorithm or some code. I am unsure exactly what Big-O is or how it relates to Big-Theta or other means of analyzing an algorithm's ...
44
votes
7answers
8k views

Why is the worst case for this function O(n^2)?

I'm trying to teach myself how to calculate BigO notation for an arbitrary function. I found this function in a textbook. The book asserts that the function is O(n2). It gives an explanation as to why ...
2
votes
1answer
181 views

Big-O Notation and Calculus [closed]

I was wondering if there are any calculus relationships implicit in Big-O notation. For example, an algorithm linear according to Big-O notation reduces the size of the problem by a constant amount ...
1
vote
3answers
320 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 was ...
-3
votes
1answer
157 views

What is the O of this operation?

Say for a given positive integer number n, you have to find a level k so that 1 + 2 + 3 + ... + k = S is below or equals n but S + k + 1 is above n. For example in python: def find_level(n): ...
11
votes
5answers
854 views

Programmaticaly finding the Landau notation (Big O or Theta notation) of an algorithm?

I'm used to search for the Landau (Big O, Theta...) notation of my algorithms by hand to make sure they are as optimized as they can be, but when the functions are getting really big and complex, it's ...
0
votes
1answer
235 views

Is the complexity of this code quasilinear time?

Algorithm explanation: based on an unsorted list I want to find the indexes of the values in another sorted list. Note that all values are unique and the two lists have the same values, only in ...
30
votes
5answers
185k 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 ...
3
votes
1answer
158 views

How should I document a method's computational complexity in the code?

I am currently working on a project that has very little documentation overall. The team is working to change that. I am doing my part, by adding xml comments to the methods I make and the ones I edit,...
31
votes
5answers
52k views

Is this a Proper “Rule” for Identifying the “Big O” Notation of an Algorithm?

I've been learning more about Big O Notation and how to calculate it based on how an algorithm is written. I came across an interesting set of "rules" for calculating an algorithms Big O notation and ...
1
vote
3answers
197 views

Big O Complexity when iterating in 3 dimensions

What time complexity would you classify the following as having? int n = 100; for(int x = 0; x < n; x++) for(int y = 0; y < n; y++) for(int z = 0; z < n; z++) DoWork(...
-3
votes
1answer
57 views

Questions around calculation of time complexity of an algorithm [duplicate]

I am a newbie to algorithms. One thing that i always get confused is about calculation of algorithm runtimes. For example: The following piece of code in Python for i in range(n): #O(?) i*=k ...
2
votes
3answers
159 views

What is the complexity of find and checking prime numbers?

I'm trying to figure out the complexities of these two functions that I've written but could not understand.def First, I thought it is supposed be O(N). But it is not clear how many times the loop ...
2
votes
2answers
326 views

Generating O(N^2) without loops [closed]

I understand you can generate an O(N^2) algorithm by using loops: eg: for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { //do something N^2 times. } } Is it ...
26
votes
7answers
14k views

What is O in Big O?

What is Big and O in Big O notation? I've read the definitions and it doesn't tell what is O pronounced as 'oh'. For example - I understand that O(n) is complexity of a linear algorithm where n could ...
0
votes
1answer
118 views

Is my reasoning to determine this algorithm's Big-O correct?

Take the following algorithm with two separate sections, and the sections do not influence each other whatsoever (the function is not recursive, as well). void algorithm(int x) { // This section ...
16
votes
9answers
26k 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 "...
-1
votes
1answer
301 views

Help with algorithmic complexity in custom merge sort implementation

I've got an implementation of the merge sort in C++ using a custom doubly linked list. I'm coming up with a big O complexity of n^2, based on the merge_sort() > slice operation. But, from what I've ...
6
votes
2answers
5k 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 "...
0
votes
2answers
616 views

What is meant with finding real and integer constants in Big Oh notation?

From my book "Data Structures & Algorithms in Java: Sixth Edition" the definition of Big Oh is the following: Let f(n) and g(n) be functions mapping positive integers to positive real numbers....
2
votes
1answer
299 views

Am I allowed to simplify terms while calculating Big O?

I want to calculate the runtime of the following function T(n) = (1+2+3+4+5+...+n)/n At first this doesnt seemed hard to me because it can be solved easily by transforming the formula T(n) = (n(n-1)...
19
votes
6answers
5k views

What do you call it when you change the Big O execution time of a function [closed]

Let's say I have a function which sorts a database in O(n^2) time. I want to go about refactoring it so it runs in O(n log(n)) time, and in doing so I will change the fundamental way the operation ...
66
votes
17answers
14k views

Is big-O really that relevant when working in industry?

In every interview I have been in, I have been quizzed on mathematical analysis of complexity, including big-O notation. How relevant is big-O analysis to development in industry? How often do you ...
0
votes
5answers
3k views

Binary Search seems superior, why did the committee of C++ still have Find in the algorithm library?

I wish to search for an integer in a vector of integer. I have two candidates for the job: Binary Search Find It seems that Binary Search is the best candidate for the job as although I have to sort ...
0
votes
3answers
157 views

Big-O when worst case numerical value is known

If I have an algorithm and part of it has a known worst case numerical value, which is reasonably small compared to the rest of the problem, is it ok to argue that part as O(1)? E.g. If part of the ...
4
votes
3answers
11k views

Finding longest subsequence with sum less than or equal to a fixed number

I was trying to solve Problem 279-B. Given an natural number, t, and an array, a[0],...,a[n-1], of natural numbers, find the maximum length of a continuous subarray, a[i],...,a[j] in a where a[i]+.....
3
votes
3answers
628 views

randomly filling in empty spaces in a matrix - O(N) amortized time?

Here are two ways to answer the following question. I'm trying to confirm what I believe their time complexity to be: If I had a snake game with a x,y matrix of spaces, some of which were occupied ...
-3
votes
1answer
1k views

What's the needed math for building algorithms? [closed]

What's the needed math for building algorithms? Because I was reading a book and I can't understand much. It says I need simple math from high school. I don't want to learn all the math that exist ...
5
votes
2answers
3k views

Can “sub-linear” still be a straight line?

I'm working on a problem that requires a "sub-linear" solution. A quick search for sub-linear will return a lot of this... ... where the sub-linear line is modelled as logarithmic/asymptotic. But I ...
-4
votes
1answer
92 views

Calculating Complexity

I am having trouble calculating the complexity of this problem: REVERSE3(A): // Reverse the order of elements in an array // P is an array; assume generating next permutation takes 1 step. for ...
2
votes
6answers
546 views

Does the workload problem belong to a class of computer science problem?

I went for an interview, and got a workload problem: Problem: write a function to tell whether a series of workloads will exceed the maximum workload or not Input: MaxWorkLoad: example 10 ...
5
votes
3answers
4k views

Loop runtime question

I had an exam today and I feel that I did pretty well, except I could not for the life of me figure out what appears to be an unbelievably simple question. We were asked to give theta notation run ...
1
vote
0answers
97 views

What does time complexity of n log n signify? [duplicate]

Is it the number of iterations or recursive calls made? Or is it the number of times the conditional check has been applied? Ex: if there are 10 elements in an array in descending order. The time ...
2
votes
4answers
2k views

Finding the first subarray that sums to a given total

Here is the question: Given and unordered array of positive and negative integers. How can you find the first subarray to sum to a given value? For example. Given the array... [1, -3, 4, 8, 2, -...
2
votes
1answer
99 views

Help with Big-O notation complexity [duplicate]

How do I find the O - notation complexity for the following? int sum = 0; for (int i = 1; i <= n*2; i++ ) sum++; I read the guide on Big - O and other posts on Big -O complexity, but I'm ...
13
votes
7answers
8k views

Big Oh notation does not mention constant value

I am a programmer and have just started reading Algorithms. I am not completely convinced with the notations namely Bog Oh, Big Omega and Big Theta. The reason is by definition of Big Oh, it states ...
-1
votes
2answers
93 views

What programming environments can be used to illustrate and benchmark the unoptimized space complexity of an algorithm?

What programming language along with implementation and compiler can I use to study the pure, unoptimized space complexity of an arbitrary algorithm? And what methods can I use to do so? For example,...
-1
votes
1answer
1k views

Big-Oh notation of a stackarray

I am studying data structures and I have hit a bit of a road block. The top is Big oh notation and it is simply confusing. While I can find the upper bound for the simplest of loops, when it comes to ...
1
vote
1answer
111 views

omega why K + N better than N

I was reviewing the big O cheatsheet at http://bigocheatsheet.com/ and ran into some listings under sort that I do not understand. Runtimes are color coded, green being better than yellow. There are ...
-1
votes
3answers
222 views

Time complexity of an algorithm [closed]

What is the complexity of the following loop? for(i=1;i<n;i=2^i) sum+=i;
1
vote
1answer
340 views

Big-O notation and halting problems

I'm trying to understand why it's impossible to create a tool that calculates Big-O notation automatically. I have read about Halting problems, but not related on Big-O notation and I was wondering, ...
-1
votes
1answer
56 views

Time complexity Computation

What will be the result of the time complexity of this piece of code i.e. int sum(int A[], int n) { int sum = 0, i; for(i = 0; i < n; i++) { sum = sum + A[i]; } ...
1
vote
1answer
620 views

Should I use this very short Python Quicksort implementation?

def quicksort(N): if len(N) < 2: return N else: less = quicksort([number for number in N[1:] if number < N[0]]) more = quicksort([number for number in N[1:] if ...
4
votes
5answers
505 views

Efficient way to calculate how many items to destroy if each has a 70% chance to be destroyed

We start with a variable that holds an integer for the "number of items" that we have somewhere, somehow. Then, the algorithm is applied: each one of those items have a 70% chance to be destroyed. ...
1
vote
2answers
142 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 ...
5
votes
8answers
3k views

How meaningful is the Big-O time complexity of an algorithm?

Programmers often talk about the time complexity of an algorithm, e.g. O(log n) or O(n^2). Time complexity classifications are made as the input size goes to infinity, but ironically infinite input ...