big-o

Computing Algorithm Complexity - Confusion

I have the following code snippet: sum = 0; for (i = 0; i < n; i++) for (j = 0; j < i; j++) sum++; The complexity would be O(n^2), but if I want to dig a little more for the internal loop complexity then would it be (n (n-1))/2 or (n-1)!? ...

Recommended Big O Notation book with .NET examples

Does anyone know of any good .NET books that focus on algorithmic complexity specifically looking at Big O Notation? The only book I have found is Data Structures and Algorithms Using C# by Michael McMillan but unfortunately (based on Amazon reviews) this does not appear to be the greatest.... Any other suggestions would be much apprec...

Proving and Disproving BigO

In proving and disproving Big O questions that explicitly say use the definition to prove and disprove, my question is, is what I am doing correct? For example you have a question that is g(n) = O(f(n)) ... In order to prove it I was doing the following g(n) <= C(F(n)) g(n)/F(n) <= C .. then give n=1 and solve for C , which proves it. ...

What is total frequency count and running time (Big-O notation)?

I have the following code snippet: 1. for (i = 1; i < n; i++) 2. for (j = 1; j < i*i; j++) 3. if(j % i == 0) 4. for(k = 0; k < j;k++) 5. sum++; What is total frequency count and running time (Big-Oh notation)? Frequency count examine a piece code and predict the number of instructions to be executed (e.g...

Big O for this recursive algorithm

I did the following algorithm involving a Binary Heap structure: Algorithm: heapMinimum(node) Input : Position n Output : Sequence minList; containing the postions that hold the minimum value 1. minList <-- sequence 2. if parent(node) == NULL // current node is the root of the tree 3. minList.insertLast(node) 4. if (leftchild(no...

What does O(log n) mean exactly?

I am currently 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 proportionally...and the same goes for, for example, quadratic time O(n2) etc..even algorithms, such as permutation generators, with O(n!) tim...

What data structure would have the fastest time for search and insert functions?

The question pretty much says it all, but I'm building a compiler and am trying to decide on what sort of data structure to use for my symbol table. Considering the only functions the symbol table will need is a search and an insert I'd like to use a data structure that can do those as quickly as possible. Any suggestions? ...

Is amortization ever really desirable?

For instance, suppose I have an algorithm that's O(n) and an algorithm that's an amortized O(n). Is it fair to say that in strictly big oh terms, the non-amortized algorithm will always be as fast or faster than the amortized algorithm? Or is there ever any reason to prefer the amortized version (ignoring things like code simplicity or...

What data structure using O(n) storage with O(log n) query time should I use for Range Minimum Queries?

I'm stumped by the following homework question for an algorithms class: Suppose that we are given a sequence of n values x1, x2 ... xn, and seek to quickly answer repeated queries of the form: given i and j, find the smallest value in xi... xj Design a data structure that uses O(n) space and answers queries in O(log n)...

Strassen's algorithm efficiency help

Hello I am trying to get the efficiency for Strassen's algorithm but need some help. The recurrence relation for the algorithm is the following: A(n) = 7A(n/2)+18(n/2)^2, for n>1, A(1) = 0. I've solved it to the point where I have a(n) = 6( 7^(log base(2) n) - 4^(log base(2) n) ) Does this mean the efficiency of the algorithm is...

How is the PHP array implemented on the C level?

The PHP array is one of the language's core features IMHO. It is sparse, allows multi-typed keys in the same array, and supports set, dictionary, array, stack/queue and iterative functionality. BUT after working with PHP for a while now, I've found that quite a few of the array_* functions are much slower than you'd think at first glanc...

Big O complexity of the basic arithmetic operations

What Big-O complexity have most widespread algorithms for the basic arithmetic operations like multiplication, square root, logarithm, scalar and matrix product? Do exist some exotic algorithms which are the most effective in terms of Big-O complexity but for some reasons not very widespread in practical solutions (e.g. not implemented i...

A good tutorial for order of complexity?

Does anyone know of some good tutorial on order of complexity that can explain it at an advanced level? probably with some examples and tricky cases? ...

Big O complexity of simple for not always linear?

I'm sure most of you know that a nested loop has O(n^2) complexity if the function input size is n for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ ... } } I think that this is similar, by a analogous argument, but i'm not sure can anyone confirm? for(int i = 0, max = n*n; i < max; i++{ ... } If so i guess that there is some...

Big o notation runtime

Hi, i have been given some code to work out big o runtimes on them, could someone tell me if i am on the right track or not?? //program1 int i, count = 0, n = 20000; for(i = 0; i < n * n; i++) { count++; } Is that O(n^2)? //number2 int i, inner_count = 0, n = 2000000000; for(i = 0; i < n; i++) { inner_count++;...

List of Big-O for PHP functions

After using PHP for a while now, I've noticed that not all PHP built in functions as fast as expected. Consider the below two possible implementations of a function that finds if a number is prime using a cached array of primes. //very slow for large $prime_array $prime_array = array( 2, 3, 5, 7, 11, 13, .... 104729, ... ); $result_arra...

Simple Big O with lg(n) proof

I'm attempting to guess and prove the Big O for: f(n) = n^3 - 7n^2 + nlg(n) + 10 I guess that big O is n^3 as it is the term with the largest order of growth However, I'm having trouble proving it. My unsuccesful attempt follows: f(n) <= cg(n) f(n) <= n^3 - 7n^2 + nlg(n) + 10 <= cn^3 f(n) <= n^3 + (n^3)*lg(n) + 10n^3 <= cn^3 f(n) <=...

How is schoolbook long division an O(n^2) algorithm?

Premise: This Wikipedia page suggests that the computational complexity of "Schoolbook" long division is O(n^2). Deduction: Instead of taking two n-digit numbers, if I take one n-digit number and one m-digit number, then the complexity would be O(n*m). Contradiction: Suppose you divide 100000000 (n digits) b...

What is the complexity of the below code with respect to memory ?

Hi, I read about Big-O Notation from here and had few questions on calculating the complexity.So for the below code i have calculated the complexity. need your inputs for the same. private void reverse(String strToRevers) { if(strToRevers.length() == 0) { return ; } else { ...

The limits of parallelism (job-interview question)

Is it possible to solve a problem of O(n!) complexity within a reasonable time given infinite number of processing units and infinite space? The typical example of O(n!) problem is brute-force search: trying all permutations (ordered combinations). ...